Skip to content

Commit 8ca0bd8

Browse files
committed
made IGroupMaker (axis.i) a valid Sequence
(added __len__ and check that key < len(axis) in IGroupMaker)
1 parent cfb6d48 commit 8ca0bd8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

larray/core/group.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,13 @@ def __init__(self, axis):
711711
self.axis = axis
712712

713713
def __getitem__(self, key):
714+
if isinstance(key, (int, np.integer)) and not isinstance(self.axis, ABCAxisReference) and key >= len(self.axis):
715+
raise IndexError("{} is out of range for axis of length {}".format(key, len(self.axis)))
714716
return IGroup(key, None, self.axis)
715717

718+
def __len__(self):
719+
return len(self.axis)
720+
716721

717722
# We need a separate class for LGroup and cannot simply create a new Axis with a subset of values/ticks/labels:
718723
# the subset of ticks/labels of the LGroup need to correspond to its *Axis* indices

0 commit comments

Comments
 (0)