From 4e00d45f686845423a755d5a85132c9b020072fb Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 12 Dec 2015 17:07:36 -0600 Subject: [PATCH] Improve warning message --- skimage/util/dtype.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/skimage/util/dtype.py b/skimage/util/dtype.py index fa2d296e..077b14be 100644 --- a/skimage/util/dtype.py +++ b/skimage/util/dtype.py @@ -126,7 +126,15 @@ def convert(image, dtype, force_copy=False, uniform=False): # Output array is of same kind as input. kind = a.dtype.kind if n > m and a.max() < 2 ** m: - warn("Downcasting directly without scaling") + mnew = int(np.ceil(m / 2) * 2) + if mnew > m: + dtype = "int%s" % mnew + else: + dtype = "uint%s" % mnew + n = int(np.ceil(n / 2) * 2) + msg = ("Downcasting %s to %s without scaling because max " + "value %s fits in %s" % (a.dtype, dtype, a.max(), dtype)) + warn(msg) return a.astype(_dtype2(kind, m)) elif n == m: return a.copy() if copy else a