@@ -341,8 +341,7 @@ def __getitem__(self, slicer):
341341 raise NotImplementedError (
342342 "Cannot slice un-makeable image types" )
343343
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 ))
346345 dataobj = self .img .dataobj [slicer ]
347346 affine = self .img ._slice_affine (slicer )
348347 return klass (dataobj .copy (), affine , self .img .header )
@@ -516,10 +515,12 @@ def _check_slicing(self, slicer, return_spatial=False):
516515 '''
517516 slicer = canonical_slicers (slicer , self .shape )
518517 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`." )
523524 return spatial_slices if return_spatial else slicer
524525
525526 def _slice_affine (self , slicer ):
0 commit comments