Skip to content

Commit

Permalink
Remove all expected warnings on prec or sign loss
Browse files Browse the repository at this point in the history
  • Loading branch information
jni committed Jun 20, 2019
1 parent 9f4fd47 commit 085cb73
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
6 changes: 2 additions & 4 deletions skimage/color/tests/test_colorconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ def test_xyz_rgb_roundtrip(self):
# RGB<->HED roundtrip with ubyte image
def test_hed_rgb_roundtrip(self):
img_rgb = img_as_ubyte(self.img_rgb)
with expected_warnings(['precision loss']):
new = img_as_ubyte(hed2rgb(rgb2hed(img_rgb)))
new = img_as_ubyte(hed2rgb(rgb2hed(img_rgb)))
assert_equal(new, img_rgb)

# RGB<->HED roundtrip with float image
Expand All @@ -189,8 +188,7 @@ def test_hdx_rgb_roundtrip(self):
img_rgb = self.img_rgb
conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
rgb_from_hdx)
with expected_warnings(['precision loss']):
assert_equal(img_as_ubyte(conv), img_rgb)
assert_equal(img_as_ubyte(conv), img_rgb)

# RGB<->HDX roundtrip with float image
def test_hdx_rgb_roundtrip_float(self):
Expand Down
3 changes: 1 addition & 2 deletions skimage/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def horse():
horse : (328, 400) bool ndarray
Horse image.
"""
with expected_warnings(['Possible precision loss', 'Possible sign loss']):
return img_as_bool(load("horse.png", as_gray=True))
return img_as_bool(load("horse.png", as_gray=True))


def clock():
Expand Down
11 changes: 4 additions & 7 deletions skimage/exposure/tests/test_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ def test_equalize_uint8_approx():


def test_equalize_ubyte():
with expected_warnings(['precision loss']):
img = util.img_as_ubyte(test_img)
img = util.img_as_ubyte(test_img)
img_eq = exposure.equalize_hist(img)

cdf, bin_edges = exposure.cumulative_distribution(img_eq)
Expand Down Expand Up @@ -277,7 +276,7 @@ def test_adapthist_grayscale():
img = util.img_as_float(data.astronaut())
img = rgb2gray(img)
img = np.dstack((img, img, img))
with expected_warnings(['precision loss|non-contiguous input']):
with expected_warnings(['non-contiguous input']):
adapted = exposure.equalize_adapthist(img, kernel_size=(57, 51),
clip_limit=0.01, nbins=128)
assert img.shape == adapted.shape
Expand All @@ -293,8 +292,7 @@ def test_adapthist_color():
warnings.simplefilter('always')
hist, bin_centers = exposure.histogram(img)
assert len(w) > 0
with expected_warnings(['precision loss']):
adapted = exposure.equalize_adapthist(img, clip_limit=0.01)
adapted = exposure.equalize_adapthist(img, clip_limit=0.01)

assert adapted.min() == 0
assert adapted.max() == 1.0
Expand All @@ -311,8 +309,7 @@ def test_adapthist_alpha():
img = util.img_as_float(data.astronaut())
alpha = np.ones((img.shape[0], img.shape[1]), dtype=float)
img = np.dstack((img, alpha))
with expected_warnings(['precision loss']):
adapted = exposure.equalize_adapthist(img)
adapted = exposure.equalize_adapthist(img)
assert adapted.shape != img.shape
img = img[:, :, :3]
full_scale = exposure.rescale_intensity(img)
Expand Down
8 changes: 2 additions & 6 deletions skimage/filters/rank/tests/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,8 @@ def test_compare_8bit_unsigned_vs_signed(self):
image = img_as_ubyte(data.camera())[::2, ::2]
image[image > 127] = 0
image_s = image.astype(np.int8)
with expected_warnings(['sign loss', 'precision loss']):
image_u = img_as_ubyte(image_s, warn_on_precision_loss=True,
warn_on_sign_loss=True)
assert_equal(image_u, img_as_ubyte(image_s,
warn_on_precision_loss=True,
warn_on_sign_loss=True))
image_u = img_as_ubyte(image_s)
assert_equal(image_u, img_as_ubyte(image_s))

methods = ['autolevel', 'bottomhat', 'equalize', 'gradient', 'maximum',
'mean', 'geometric_mean', 'subtract_mean', 'median', 'minimum',
Expand Down
15 changes: 5 additions & 10 deletions skimage/util/tests/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def test_range(dtype, f_and_dt):

f, dt = f_and_dt

with expected_warnings([r'precision loss|sign loss|\A\Z']):
y = f(x)
y = f(x)

omin, omax = dtype_range[dt]

Expand Down Expand Up @@ -72,8 +71,7 @@ def test_range_extra_dtypes(dtype_in, dt):
imin, imax = dtype_range_extra[dtype_in]
x = np.linspace(imin, imax, 10).astype(dtype_in)

with expected_warnings([r'precision loss|sign loss|\A\Z']):
y = convert(x, dt, warn_on_precision_loss=True, warn_on_sign_loss=True)
y = convert(x, dt)

omin, omax = dtype_range_extra[dt]
_verify_range("From %s to %s" % (np.dtype(dtype_in), np.dtype(dt)),
Expand Down Expand Up @@ -132,12 +130,9 @@ def test_clobber():
for func_output_type in img_funcs:
img = np.random.rand(5, 5)

# UserWarning for possible precision loss, expected
with expected_warnings([r'Possible precision loss|\A\Z',
r'Possible sign loss|\A\Z']):
img_in = func_input_type(img)
img_in_before = img_in.copy()
img_out = func_output_type(img_in)
img_in = func_input_type(img)
img_in_before = img_in.copy()
img_out = func_output_type(img_in)

assert_equal(img_in, img_in_before)

Expand Down

0 comments on commit 085cb73

Please sign in to comment.