Skip to content

Commit 5577eb8

Browse files
committed
TEST: Revise equality check to approximate
get_fdata(dtype=float32) and get_fdata(dtype=float64).astype(float32) are no longer equivalent
1 parent dfebe58 commit 5577eb8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

nibabel/tests/test_image_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from nose import SkipTest
4545
from nose.tools import (assert_true, assert_false, assert_raises, assert_equal)
4646

47-
from numpy.testing import assert_almost_equal, assert_array_equal, assert_warns
47+
from numpy.testing import assert_almost_equal, assert_array_equal, assert_warns, assert_allclose
4848
from ..testing import clear_and_catch_warnings
4949
from ..tmpdirs import InTemporaryDirectory
5050

@@ -314,18 +314,18 @@ def _check_proxy_interface(self, imaker, meth_name):
314314
# New data dtype, no caching, doesn't use or alter cache
315315
fdata_new_dt = img.get_fdata(caching='unchanged', dtype='f4')
316316
# We get back the original read, not the modified cache
317-
assert_array_equal(fdata_new_dt, proxy_data.astype('f4'))
317+
assert_allclose(fdata_new_dt, proxy_data.astype('f4'), rtol=1e-05, atol=1e-08)
318318
assert_equal(fdata_new_dt.dtype, np.float32)
319319
# The original cache stays in place, for default float64
320320
assert_array_equal(img.get_fdata(), 42)
321321
# And for not-default float32, because we haven't cached
322322
fdata_new_dt[:] = 43
323323
fdata_new_dt = img.get_fdata(caching='unchanged', dtype='f4')
324-
assert_array_equal(fdata_new_dt, proxy_data.astype('f4'))
324+
assert_allclose(fdata_new_dt, proxy_data.astype('f4'), rtol=1e-05, atol=1e-08)
325325
# Until we reset with caching='fill', at which point we
326326
# drop the original float64 cache, and have a float32 cache
327327
fdata_new_dt = img.get_fdata(caching='fill', dtype='f4')
328-
assert_array_equal(fdata_new_dt, proxy_data.astype('f4'))
328+
assert_allclose(fdata_new_dt, proxy_data.astype('f4'), rtol=1e-05, atol=1e-08)
329329
# We're using the cache, for dtype='f4' reads
330330
fdata_new_dt[:] = 43
331331
assert_array_equal(img.get_fdata(dtype='f4'), 43)

0 commit comments

Comments
 (0)