@@ -439,6 +439,9 @@ def test_slicer(self):
439439 assert_array_equal (downsampled_img .header .get_zooms ()[:3 ],
440440 np .array (spatial_zooms ) * 2 )
441441
442+ max4d = (hasattr (img .header , '_header_data' ) and
443+ 'dims' in img .header ._header_data .dtype .fields and
444+ img .header ._header_data ['dims' ].shape == (4 ,))
442445 # Check newaxis errors
443446 if t_axis == 3 :
444447 with assert_raises (IndexError ):
@@ -460,17 +463,26 @@ def test_slicer(self):
460463 with assert_raises (IndexError ):
461464 img .slicer [:, :, :, None ]
462465 elif len (img .shape ) == 4 :
463- # Reorder non-spatial axes
464- assert_equal (img .slicer [:, :, :, None ].shape , img .shape [:3 ] + (1 ,) + img .shape [3 :])
466+ if max4d :
467+ with assert_raises (ValueError ):
468+ img .slicer [:, :, :, None ]
469+ else :
470+ # Reorder non-spatial axes
471+ assert_equal (img .slicer [:, :, :, None ].shape ,
472+ img .shape [:3 ] + (1 ,) + img .shape [3 :])
465473 else :
466474 # 3D Analyze/NIfTI/MGH to 4D
467475 assert_equal (img .slicer [:, :, :, None ].shape , img .shape + (1 ,))
468476 if len (img .shape ) == 3 :
469477 # Slices exceed dimensions
470478 with assert_raises (IndexError ):
471479 img .slicer [:, :, :, :, None ]
480+ elif max4d :
481+ with assert_raises (ValueError ):
482+ img .slicer [:, :, :, :, None ]
472483 else :
473- assert_equal (img .slicer [:, :, :, :, None ].shape , img .shape + (1 ,))
484+ assert_equal (img .slicer [:, :, :, :, None ].shape ,
485+ img .shape + (1 ,))
474486
475487 # Crop by one voxel in each dimension
476488 if len (img .shape ) == 3 or t_axis == 3 :
@@ -508,7 +520,7 @@ def test_slicer(self):
508520 np .random .choice (slice_elems , n_elems ).tolist ())
509521 try :
510522 sliced_img = img .slicer [sliceobj ]
511- except IndexError :
523+ except ( IndexError , ValueError ) :
512524 # Only checking valid slices
513525 pass
514526 else :
0 commit comments