@@ -341,8 +341,7 @@ def __getitem__(self, slicer):
341
341
raise NotImplementedError (
342
342
"Cannot slice un-makeable image types" )
343
343
344
- slicer = self .img ._check_slicing (self ._arr_to_slice (slicer ),
345
- self .img .shape )
344
+ slicer = self .img ._check_slicing (self ._arr_to_slice (slicer ))
346
345
dataobj = self .img .dataobj [slicer ]
347
346
affine = self .img ._slice_affine (slicer )
348
347
return klass (dataobj .copy (), affine , self .img .header )
@@ -516,10 +515,12 @@ def _check_slicing(self, slicer, return_spatial=False):
516
515
'''
517
516
slicer = canonical_slicers (slicer , self .shape )
518
517
spatial_slices = slicer [self ._spatial_dims ]
519
- if any (not isinstance (subslicer , (slice , None ))
520
- for subslicer in spatial_slices ):
521
- raise IndexError ("Scalar indices disallowed in spatial dimensions; "
522
- "Use `[x]` or `x:x+1`." )
518
+ for subslicer in spatial_slices :
519
+ if subslicer is None :
520
+ raise IndexError ("New axis not permitted in spatial dimensions" )
521
+ elif isinstance (subslicer , int ):
522
+ raise IndexError ("Scalar indices disallowed in spatial dimensions; "
523
+ "Use `[x]` or `x:x+1`." )
523
524
return spatial_slices if return_spatial else slicer
524
525
525
526
def _slice_affine (self , slicer ):
0 commit comments