Skip to content

Commit

Permalink
feat: Add support for accessing nested items in BoxList using numpy-s…
Browse files Browse the repository at this point in the history
…tyle tuple indexing.
  • Loading branch information
Bit0r committed Apr 18, 2024
1 parent cc26a46 commit b5f00b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions box/box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def __getitem__(self, item):
if len(list_pos.group()) == len(item):
return value
return value.__getitem__(item[len(list_pos.group()) :].lstrip("."))
if isinstance(item, tuple):
result = self
for i in item:
result = result[i]
return result
return super().__getitem__(item)

def __delitem__(self, key):
Expand Down
2 changes: 2 additions & 0 deletions test/test_box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def test_box_list(self):
assert new_list[-1].item == 22
new_list.append([{"bad_item": 33}])
assert new_list[-1][0].bad_item == 33
new_list[-1].append([{"bad_item": 33}])
assert new_list[-1, -1, 0].bad_item == 33
assert repr(new_list).startswith("BoxList(")
for x in new_list.to_list():
assert not isinstance(x, (BoxList, Box))
Expand Down

0 comments on commit b5f00b0

Please sign in to comment.