diff --git a/encord/objects/classification_instance.py b/encord/objects/classification_instance.py index 67556c67..061fdfe0 100644 --- a/encord/objects/classification_instance.py +++ b/encord/objects/classification_instance.py @@ -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: @@ -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, @@ -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) diff --git a/tests/objects/test_label_structure.py b/tests/objects/test_label_structure.py index 9e232422..8ded1de7 100644 --- a/tests/objects/test_label_structure.py +++ b/tests/objects/test_label_structure.py @@ -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) @@ -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) @@ -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)]))