Skip to content

Commit

Permalink
Merge pull request #1698 from souhhmm/fix/xyxy-shape-crash
Browse files Browse the repository at this point in the history
fix: is_empty check for filtering
  • Loading branch information
LinasKo authored Dec 4, 2024
2 parents 3d14167 + 7141f11 commit ae8e6b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions supervision/detection/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,8 @@ def __getitem__(
"""
if isinstance(index, str):
return self.data.get(index)
if self.is_empty():
return Detections.empty()
if isinstance(index, int):
index = [index]
return Detections(
Expand Down
6 changes: 6 additions & 0 deletions test/detection/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@
None,
pytest.raises(IndexError),
),
(
Detections.empty(),
np.isin(Detections.empty()["class_name"], ["cat", "dog"]),
Detections.empty(),
DoesNotRaise(),
), # Filter an empty detections by specific class names
],
)
def test_getitem(
Expand Down

0 comments on commit ae8e6b2

Please sign in to comment.