Skip to content

Commit

Permalink
Ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
clinton-encord committed Jan 3, 2025
1 parent f2dd1fd commit dbcb6c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
18 changes: 5 additions & 13 deletions encord/objects/classification_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,13 @@

# For Audio and Text files, classifications can only be applied to Range(start=0, end=0)
# Because we treat the entire file as being on one frame (for classifications, its different for objects)
def _verify_non_geometric_classifications_range(
ranges_to_add: Ranges,
label_row: Optional[LabelRowV2]
) -> None:
is_range_only_on_frame_0 = (len(ranges_to_add) == 1
and ranges_to_add[0].start == 0
and ranges_to_add[0].end == 0)
if (label_row is not None
and not is_geometric(label_row.data_type)
and not is_range_only_on_frame_0):
def _verify_non_geometric_classifications_range(ranges_to_add: Ranges, label_row: Optional[LabelRowV2]) -> None:
is_range_only_on_frame_0 = len(ranges_to_add) == 1 and ranges_to_add[0].start == 0 and ranges_to_add[0].end == 0
if label_row is not None and not is_geometric(label_row.data_type) and not is_range_only_on_frame_0:
raise LabelRowError(
"For audio files and text files, classifications can only be attached to frame=0 "
"You may use `ClassificationInstance.set_for_frames(frames=Range(start=0, end=0))`.")
"You may use `ClassificationInstance.set_for_frames(frames=Range(start=0, end=0))`."
)


class ClassificationInstance:
Expand Down Expand Up @@ -152,7 +146,6 @@ def _set_for_ranges(
frames: Frames,
overwrite: bool,
created_at: Optional[datetime],

created_by: Optional[str],
confidence: float,
manual_annotation: bool,
Expand All @@ -173,7 +166,6 @@ def _set_for_ranges(
f"Set 'overwrite' parameter to True to override."
)


for range_to_add in ranges_to_add:
self._check_within_range(range_to_add.end)

Expand Down
28 changes: 15 additions & 13 deletions tests/objects/test_label_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,13 @@ def test_add_and_get_classification_instances_to_audio_label_row(ontology):

with pytest.raises(LabelRowError) as e:
label_row.add_classification_instance(overlapping_classification_instance)

assert e.value.message == (f"A ClassificationInstance '{overlapping_classification_instance.classification_hash}' was already added "
"and has overlapping frames. Overlapping frames that were "
"found are `[(0:0)]`. Make sure that you only add classifications "
"which are on frames where the same type of classification does not yet exist.")

assert e.value.message == (
f"A ClassificationInstance '{overlapping_classification_instance.classification_hash}' was already added "
"and has overlapping frames. Overlapping frames that were "
"found are `[(0:0)]`. Make sure that you only add classifications "
"which are on frames where the same type of classification does not yet exist."
)

# Do not raise if overwrite flag is passed
overlapping_classification_instance.set_for_frames(0, overwrite=True)
Expand Down Expand Up @@ -1127,10 +1129,10 @@ def test_non_range_classification_cannot_be_added_to_audio_label_row(ontology):


def test_non_geometric_label_rows_can_only_have_classifications_on_frame_0(
ontology,
empty_audio_label_row: LabelRowV2,
empty_plain_text_label_row: LabelRowV2,
empty_html_text_label_row: LabelRowV2,
ontology,
empty_audio_label_row: LabelRowV2,
empty_plain_text_label_row: LabelRowV2,
empty_html_text_label_row: LabelRowV2,
):
for label_row in [empty_audio_label_row, empty_html_text_label_row, empty_plain_text_label_row]:
classification_instance = ClassificationInstance(checklist_classification, range_only=True)
Expand All @@ -1140,13 +1142,13 @@ def test_non_geometric_label_rows_can_only_have_classifications_on_frame_0(
with pytest.raises(LabelRowError) as e:
classification_instance.set_for_frames(Range(start=0, end=1))

assert e.value.message == ("For audio files and text files, classifications can only be "
"attached to frame=0 You may use "
"`ClassificationInstance.set_for_frames(frames=Range(start=0, end=0))`."
assert e.value.message == (
"For audio files and text files, classifications can only be "
"attached to frame=0 You may use "
"`ClassificationInstance.set_for_frames(frames=Range(start=0, end=0))`."
)



def test_audio_object_exceed_max_frames(ontology, empty_audio_label_row: LabelRowV2):
object_instance = ObjectInstance(audio_obj_ontology_item)
object_instance.set_for_frames(AudioCoordinates(range=[Range(start=0, end=100)]))
Expand Down

0 comments on commit dbcb6c3

Please sign in to comment.