Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/crowsetta/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def __init__(
if seq is not None and bboxes is not None:
raise ValueError("an Annotation can have either a ``seq``" "or ``bboxes``, but not both.")

if seq:
if seq is not None:
if not (
isinstance(seq, crowsetta.Sequence)
or (isinstance(seq, list) and all([isinstance(seq_, crowsetta.Sequence) for seq_ in seq]))
):
raise TypeError(f"``seq`` should be a crowsetta.Sequence or list of Sequences but was: {type(seq)}")
self.seq = seq

if bboxes:
if bboxes is not None:
if not isinstance(bboxes, list):
raise ValueError("``bboxes`` should be a list")
if not all([isinstance(bbox, BBox) for bbox in bboxes]):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,16 @@ def bbox_not_list_raises():
def bbox_not_list_of_bboxes_raises():
with pytest.raises(ValueError):
crowsetta.Annotation(annot_path="./an/annnot.csv", notated_path=None, bboxes=[_ for _ in range(10)])


def test_seq_with_no_segments():
"""Test that an :class:`crowsetta.Annotation`
instantiated with a :class:`crowsetta.Sequence`
that has no segments / a length of zero
has a `seq` attribute that points to that Sequence.
"""
# see https://github.com/vocalpy/crowsetta/issues/290
seq = crowsetta.Sequence.from_keyword(labels=[], onsets_s=[], offsets_s=[])
annot = crowsetta.Annotation(seq=seq, annot_path="./path.csv")
assert hasattr(annot, "seq")
assert annot.seq == seq
Loading