Skip to content

Commit d4cf55f

Browse files
authored
Merge pull request #1221 from effigies/fix/test-slicing
FIX: Catch random bad slice when testing image slicing
2 parents e221d77 + 8bb1b99 commit d4cf55f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

nibabel/tests/test_spatialimages.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,15 @@ def test_slicer(self):
540540
sliceobj = tuple(np.random.choice(slice_elems, n_elems))
541541
try:
542542
sliced_img = img.slicer[sliceobj]
543-
except (IndexError, ValueError):
544-
# Only checking valid slices
545-
pass
546-
else:
547-
sliced_data = in_data[sliceobj]
548-
assert (sliced_data == sliced_img.get_fdata()).all()
549-
assert (sliced_data == sliced_img.dataobj).all()
550-
assert (sliced_data == img.dataobj[sliceobj]).all()
551-
assert (sliced_data == img.get_fdata()[sliceobj]).all()
543+
except (IndexError, ValueError, HeaderDataError):
544+
# Skip invalid slices or images that can't be created
545+
continue
546+
547+
sliced_data = in_data[sliceobj]
548+
assert np.array_equal(sliced_data, sliced_img.get_fdata())
549+
assert np.array_equal(sliced_data, sliced_img.dataobj)
550+
assert np.array_equal(sliced_data, img.dataobj[sliceobj])
551+
assert np.array_equal(sliced_data, img.get_fdata()[sliceobj])
552552

553553

554554
class MmapImageMixin:

0 commit comments

Comments
 (0)