8000 Backport PR #4681: Reintroduced convert with a strong deprecation war… · scikit-image/scikit-image@b652e05 · GitHub
[go: up one dir, main page]

Skip to content

Commit b652e05

Browse files
Backport PR #4681: Reintroduced convert with a strong deprecation warning (#4693)
Co-authored-by: Mark Harfouche <mark.harfouche@gmail.com>
1 parent e58af6a commit b652e05

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

skimage/util/dtype.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,28 @@ def _convert(image, dtype, force_copy=False, uniform=False):
349349
return image.astype(dtype_out)
350350

351351

352+
def convert(image, dtype, force_copy=False, uniform=False):
353+
warn("The use of this function is discouraged as its behavior may change "
354+
"dramatically in scikit-image 1.0. This function will be removed"
355+
"in scikit-image 1.0.", FutureWarning, stacklevel=2)
356+
return _convert(image=image, dtype=dtype,
357+
force_copy=force_copy, uniform=uniform)
358+
359+
360+
if _convert.__doc__ is not None:
361+
convert.__doc__ = _convert.__doc__ + """
362+
363+
Warns
364+
-----
365+
FutureWarning:
366+
.. versionadded:: 0.17
367+
368+
The use of this function is discouraged as its behavior may change
369+
dramatically in scikit-image 1.0. This function will be removed
370+
in scikit-image 1.0.
371+
"""
372+
373+
352374
def img_as_float32(image, force_copy=False):
353375
"""Convert an image to single-precision (32-bit) floating point format.
354376

skimage/util/tests/test_dtype.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,22 @@ def test_float_conversion_dtype():
167167
assert y.dtype == np.dtype(dtype_out)
168168

169169

170+
def test_float_conversion_dtype_warns():
171+
"""Test that convert issues a warning when called"""
172+
from skimage.util.dtype import convert
173+
x = np.array([-1, 1])
174+
175+
# Test all combinations of dtypes convertions
176+
dtype_combin = np.array(np.meshgrid(float_dtype_list,
177+
float_dtype_list)).T.reshape(-1, 2)
178+
179+
for dtype_in, dtype_out in dtype_combin:
180+
x = x.astype(dtype_in)
181+
with expected_warnings(["The use of this function is discouraged"]):
182+
y = convert(x, dtype_out)
183+
assert y.dtype == np.dtype(dtype_out)
184+
185+
170186
def test_subclass_conversion():
171187
"""Check subclass conversion behavior"""
172188
x = np.array([-1, 1])

0 commit comments

Comments
 (0)
0