Skip to content

Commit 10eb2d0

Browse files
committed
ENH: Enable minimally-fancy indexing
1 parent fb1e4f1 commit 10eb2d0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

nibabel/fileslice.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def is_fancy(sliceobj):
5454
# slice or Ellipsis or None OK for basic
5555
if isinstance(slicer, slice) or slicer in (None, Ellipsis):
5656
continue
57+
# Allow single items in a dimension to be sliced
58+
ary = np.asanyarray(slicer)
59+
if ary.shape == (1,):
60+
slicer = ary[0]
5761
try:
5862
int(slicer)
5963
except TypeError:
@@ -113,9 +117,16 @@ def canonical_slicers(sliceobj, shape, check_inds=True):
113117
can_slicers.extend((slice(None),) * n_ellided)
114118
n_real += n_ellided
115119
continue
116-
# int / slice indexing cases
120+
# int / [int] / slice indexing cases
117121
dim_len = shape[n_real]
118122
n_real += 1
123+
124+
# Treat [x] as "x:x+1"
125+
ary = np.asanyarray(slicer)
126+
if ary.shape == (1,):
127+
can_slicers.append(slice(int(ary[0]), int(ary[0]) + 1))
128+
continue
129+
119130
try: # test for integer indexing
120131
slicer = int(slicer)
121132
except TypeError: # should be slice object

0 commit comments

Comments
 (0)