Skip to content

Commit 4e77024

Browse files
committed
TEST: Suppress new numpy warning on nan-to-int cast
1 parent f469c68 commit 4e77024

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

nibabel/tests/test_volumeutils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def test_a2f_nan2zero():
413413
# How weird? Look at arr.astype(np.int64)
414414
with np.errstate(invalid='ignore'):
415415
data_back = write_return(arr, str_io, np.int64, nan2zero=False)
416-
assert_array_equal(data_back, arr.astype(np.int64))
416+
assert_array_equal(data_back, arr.astype(np.int64))
417417

418418

419419
def test_a2f_nan2zero_scaling():
@@ -692,9 +692,15 @@ def test_a2f_nan2zero_range():
692692
write_return(arr_no_nan, fobj, np.int8, intercept=129)
693693
# OK with nan2zero false, but we get whatever nan casts to
694694
with pytest.warns(warn_type) if warn_type else error_warnings():
695-
nan_cast = np.array(np.nan, dtype=dt).astype(np.int8)
695+
# XXX NP1.24
696+
# Casting nan to int will produce a RuntimeWarning in numpy 1.24
697+
# Change to expecting this warning when this becomes our minimum
698+
with np.errstate(invalid='ignore'):
699+
nan_cast = np.array(np.nan, dtype=dt).astype(np.int8)
696700
with pytest.warns(warn_type) if warn_type else error_warnings():
697-
back_arr = write_return(arr, fobj, np.int8, intercept=129, nan2zero=False)
701+
# XXX NP1.24 - expect RuntimeWarning
702+
with np.errstate(invalid='ignore'):
703+
back_arr = write_return(arr, fobj, np.int8, intercept=129, nan2zero=False)
698704
assert_array_equal([-128, -128, -128, nan_cast], back_arr)
699705
# divslope
700706
with pytest.warns(warn_type) if warn_type else error_warnings():
@@ -706,8 +712,10 @@ def test_a2f_nan2zero_range():
706712
write_return(arr_no_nan, fobj, np.int8, intercept=257.1, divslope=2)
707713
# OK with nan2zero false
708714
with pytest.warns(warn_type) if warn_type else error_warnings():
709-
back_arr = write_return(arr, fobj, np.int8,
710-
intercept=257.1, divslope=2, nan2zero=False)
715+
# XXX NP1.24 - expect RuntimeWarning
716+
with np.errstate(invalid='ignore'):
717+
back_arr = write_return(arr, fobj, np.int8,
718+
intercept=257.1, divslope=2, nan2zero=False)
711719
assert_array_equal([-128, -128, -128, nan_cast], back_arr)
712720

713721

0 commit comments

Comments
 (0)