Skip to content

Commit

Permalink
Ignore arch specific cast warnings in tests (#7393)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lagru committed Apr 13, 2024
1 parent 55998da commit 7ae4fd8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 13 additions & 1 deletion skimage/filters/tests/test_unsharp_mask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import numpy as np
import pytest

Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions skimage/transform/tests/test_pyramids.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import warnings

import pytest
import numpy as np
Expand Down Expand Up @@ -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])

0 comments on commit 7ae4fd8

Please sign in to comment.