Skip to content

Commit a1ddae8

Browse files
committed
FIX: ComplexWarning
1 parent 5eb5e54 commit a1ddae8

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

nibabel/tests/test_proxy_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757

5858
h5py, have_h5py, _ = optional_package('h5py')
5959

60+
try:
61+
from numpy.exceptions import ComplexWarning
62+
except ImportError: # NumPy < 1.25
63+
from numpy import ComplexWarning
64+
6065

6166
def _some_slicers(shape):
6267
ndim = len(shape)
@@ -143,7 +148,7 @@ def validate_array_interface_with_dtype(self, pmaker, params):
143148
if np.issubdtype(orig.dtype, np.complexfloating):
144149
context = clear_and_catch_warnings()
145150
context.__enter__()
146-
warnings.simplefilter('ignore', np.ComplexWarning)
151+
warnings.simplefilter('ignore', ComplexWarning)
147152

148153
for dtype in sctypes['float'] + sctypes['int'] + sctypes['uint']:
149154
# Directly coerce with a dtype

nibabel/tests/test_volumeutils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969

7070
FP_RUNTIME_WARN = Version(np.__version__) >= Version('1.24.0.dev0+239')
7171

72+
try:
73+
from numpy.exceptions import ComplexWarning
74+
except ModuleNotFoundError: # NumPy < 1.25
75+
from numpy import ComplexWarning
76+
7277

7378
def test__is_compressed_fobj():
7479
# _is_compressed helper function
@@ -610,7 +615,7 @@ def test_a2f_bad_scaling():
610615
if np.issubdtype(in_type, np.complexfloating) and not np.issubdtype(
611616
out_type, np.complexfloating
612617
):
613-
cm = pytest.warns(np.ComplexWarning)
618+
cm = pytest.warns(ComplexWarning)
614619
if (slope, inter) == (1, 0):
615620
with cm:
616621
assert_array_equal(
@@ -650,7 +655,7 @@ def test_a2f_nan2zero_range():
650655
arr = np.array([-1, 0, 1, np.nan], dtype=dt)
651656
# Error occurs for arrays without nans too
652657
arr_no_nan = np.array([-1, 0, 1, 2], dtype=dt)
653-
complex_warn = (np.ComplexWarning,) if np.issubdtype(dt, np.complexfloating) else ()
658+
complex_warn = (ComplexWarning,) if np.issubdtype(dt, np.complexfloating) else ()
654659
# Casting nan to int will produce a RuntimeWarning in numpy 1.24
655660
nan_warn = (RuntimeWarning,) if FP_RUNTIME_WARN else ()
656661
c_and_n_warn = complex_warn + nan_warn

0 commit comments

Comments
 (0)