10000 fixed bug with negative stop value in slice · flyinger/spatialmath-python@260e935 · GitHub
[go: up one dir, main page]

Skip to content

Commit 260e935

Browse files
committed
fixed bug with negative stop value in slice
1 parent 90fc1db commit 260e935

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

spatialmath/smuserlist.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,16 @@ def __getitem__(self, i):
245245
"""
246246

247247
if isinstance(i, slice):
248-
return self.__class__([self.data[k] for k in range(i.start or 0, i.stop or len(self), i.step or 1)])
248+
if i.stop is None:
249+
# stop not given
250+
end = len(self)
251+
elif i.stop < 0:
252+
# stop is negative, -
253+
end = i.stop + len(self) + 1
254+
else:
255+
# stop is positive, use it directly
256+
end = i.stop
257+
return self.__class__([self.data[k] for k in range(i.start or 0, end, i.step or 1)])
249258
else:
250259
return self.__class__(self.data[i])
251260

0 commit comments

Comments
 (0)
0