From 7ae4fd8833391a3fa6f28b12a53a177699518764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gr=C3=BCter?= Date: Sat, 13 Apr 2024 03:13:51 +0200 Subject: [PATCH] Ignore arch specific cast warnings in tests (#7393) Apparently astype(...) raises a warning on some platforms despite `casting="unsafe"` being the default. I couldn't reproduce this as I don't have access to the architectures this fails for [1, 2], but these warnings should be harmless to ignore for these tests. [1] https://www.github.com/scikit-image/scikit-image/issues/7391 [2] https://buildd.debian.org/status/logs.php?pkg=skimage&ver=0.23.1-1&suite=sid --- skimage/filters/tests/test_unsharp_mask.py | 14 +++++++++++++- skimage/transform/tests/test_pyramids.py | 13 +++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/skimage/filters/tests/test_unsharp_mask.py b/skimage/filters/tests/test_unsharp_mask.py index 991d5ec6743..676d1abf215 100644 --- a/skimage/filters/tests/test_unsharp_mask.py +++ b/skimage/filters/tests/test_unsharp_mask.py @@ -1,3 +1,5 @@ +import warnings + import numpy as np import pytest @@ -38,7 +40,17 @@ def test_unsharp_masking_output_type_and_shape( radius, amount, shape, multichannel, dtype, offset, preserve ): array = np.random.random(shape) - array = ((array + offset) * 128).astype(dtype) + array = (array + offset) * 128 + with warnings.catch_warnings(): + # Ignore arch specific warning on arm64, armhf, ppc64el, riscv64, s390x + # https://github.com/scikit-image/scikit-image/issues/7391 + warnings.filterwarnings( + action="ignore", + category=RuntimeWarning, + message="invalid value encountered in cast", + ) + array = array.astype(dtype) + if (preserve is False) and (dtype in [np.float32, np.float64]): array /= max(np.abs(array).max(), 1.0) channel_axis = -1 if multichannel else None diff --git a/skimage/transform/tests/test_pyramids.py b/skimage/transform/tests/test_pyramids.py index 57657998358..d111a5d7076 100644 --- a/skimage/transform/tests/test_pyramids.py +++ b/skimage/transform/tests/test_pyramids.py @@ -1,4 +1,5 @@ import math +import warnings import pytest import numpy as np @@ -194,8 +195,16 @@ def test_check_factor(): 'pyramid_func', [pyramids.pyramid_gaussian, pyramids.pyramid_laplacian] ) def test_pyramid_dtype_support(pyramid_func, dtype): - img = np.random.randn(32, 8).astype(dtype) - pyramid = pyramid_func(img) + with warnings.catch_warnings(): + # Ignore arch specific warning on arm64, armhf, ppc64el, riscv64, s390x + # https://github.com/scikit-image/scikit-image/issues/7391 + warnings.filterwarnings( + action="ignore", + category=RuntimeWarning, + message="invalid value encountered in cast", + ) + img = np.random.randn(32, 8).astype(dtype) + pyramid = pyramid_func(img) float_dtype = _supported_float_type(dtype) assert np.all([im.dtype == float_dtype for im in pyramid])