Skip to content

Commit 1bc593c

Browse files
committed
FIX: Test val equiv
1 parent e3a7495 commit 1bc593c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

nibabel/tests/test_floating.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,15 @@ def test_as_int():
159159
ctx = pytest.raises(OverflowError)
160160
else:
161161
ctx = nullcontext()
162+
out_val = None
162163
with ctx:
163-
as_int(val)
164+
out_val = as_int(val)
165+
if out_val is not None:
166+
assert out_val == val
164167
with ctx:
165-
as_int(-val)
168+
out_val = as_int(-val)
169+
if out_val is not None:
170+
assert out_val == -val
166171

167172

168173
def test_int_to_float():

nibabel/tests/test_volumeutils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
NUMERIC_TYPES = CFLOAT_TYPES + IUINT_TYPES
6969

7070
FP_RUNTIME_WARN = Version(np.__version__) >= Version('1.24.0.dev0+239')
71+
NP_2 = Version(np.__version__) >= Version('2.0.0.dev0')
7172

7273
try:
7374
from numpy.exceptions import ComplexWarning
@@ -743,9 +744,13 @@ def test_apply_scaling():
743744
i16_arr = np.zeros((1,), dtype=np.int16)
744745
# Check float upcast (not the normal numpy scalar rule)
745746
# This is the normal rule - no upcast from Python scalar
746-
# (on NumPy 2.0 it *will* upcast from a np.float64 scalar!)
747747
assert (f32_arr * 1.0).dtype == np.float32
748748
assert (f32_arr + 1.0).dtype == np.float32
749+
# This is the normal rule - no upcast from scalar
750+
# before NumPy 2.0, after 2.0, it upcasts
751+
want_dtype = np.float64 if NP_2 else np.float32
752+
assert (f32_arr * f64(1)).dtype == want_dtype
753+
assert (f32_arr + f64(1)).dtype == want_dtype
749754
# The function does upcast though
750755
ret = apply_read_scaling(np.float32(0), np.float64(2))
751756
assert ret.dtype == np.float64

0 commit comments

Comments
 (0)