Skip to content

Commit c906e04

Browse files
chore: drop underscore (#1063)
Co-authored-by: Clinton Wee <[email protected]>
1 parent 2633f85 commit c906e04

18 files changed

+217
-212
lines changed

encord/objects/ontology_labels_impl.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,19 @@ def get_frame_number(self, image_hash: str) -> Optional[int]:
846846
raise LabelRowError("This function is only supported for label rows of image or image group data types.")
847847
return self._label_row_read_only_data.image_hash_to_frame[image_hash]
848848

849-
def _get_spaces(self) -> list[Space]:
849+
def get_spaces(self) -> list[Space]:
850+
"""Retrieves all spaces in the data unit.
851+
852+
Use this to view the available spaces. To work on a specific space, we
853+
recommend using `LabelRowV2.get_space()`.
854+
855+
Returns:
856+
A list of all Space objects.
857+
"""
850858
return list(self._space_map.values())
851859

852860
@overload
853-
def _get_space(
861+
def get_space(
854862
self,
855863
*,
856864
id: str,
@@ -859,74 +867,74 @@ def _get_space(
859867
pass
860868

861869
@overload
862-
def _get_space(self, *, id: str, type_: Literal["image"]) -> ImageSpace:
870+
def get_space(self, *, id: str, type_: Literal["image"]) -> ImageSpace:
863871
pass
864872

865873
@overload
866-
def _get_space(self, *, id: str, type_: Literal["image_sequence"]) -> VideoSpace:
874+
def get_space(self, *, id: str, type_: Literal["image_sequence"]) -> VideoSpace:
867875
pass
868876

869877
@overload
870-
def _get_space(self, *, id: str, type_: Literal["audio"]) -> AudioSpace:
878+
def get_space(self, *, id: str, type_: Literal["audio"]) -> AudioSpace:
871879
pass
872880

873881
@overload
874-
def _get_space(self, *, id: str, type_: Literal["text"]) -> TextSpace:
882+
def get_space(self, *, id: str, type_: Literal["text"]) -> TextSpace:
875883
pass
876884

877885
@overload
878-
def _get_space(self, *, id: str, type_: Literal["html"]) -> HTMLSpace:
886+
def get_space(self, *, id: str, type_: Literal["html"]) -> HTMLSpace:
879887
pass
880888

881889
@overload
882-
def _get_space(self, *, id: str, type_: Literal["medical_file"]) -> MedicalFileSpace:
890+
def get_space(self, *, id: str, type_: Literal["medical_file"]) -> MedicalFileSpace:
883891
pass
884892

885893
@overload
886-
def _get_space(self, *, id: str, type_: Literal["medical_stack"]) -> MedicalStackSpace:
894+
def get_space(self, *, id: str, type_: Literal["medical_stack"]) -> MedicalStackSpace:
887895
pass
888896

889897
@overload
890-
def _get_space(self, *, id: str, type_: Literal["pdf"]) -> PdfSpace:
898+
def get_space(self, *, id: str, type_: Literal["pdf"]) -> PdfSpace:
891899
pass
892900

893901
@overload
894-
def _get_space(self, *, layout_key: str, type_: Literal["video"]) -> VideoSpace:
902+
def get_space(self, *, layout_key: str, type_: Literal["video"]) -> VideoSpace:
895903
pass
896904

897905
@overload
898-
def _get_space(self, *, layout_key: str, type_: Literal["image"]) -> ImageSpace:
906+
def get_space(self, *, layout_key: str, type_: Literal["image"]) -> ImageSpace:
899907
pass
900908

901909
@overload
902-
def _get_space(self, *, layout_key: str, type_: Literal["image_sequence"]) -> VideoSpace:
910+
def get_space(self, *, layout_key: str, type_: Literal["image_sequence"]) -> VideoSpace:
903911
pass
904912

905913
@overload
906-
def _get_space(self, *, layout_key: str, type_: Literal["audio"]) -> AudioSpace:
914+
def get_space(self, *, layout_key: str, type_: Literal["audio"]) -> AudioSpace:
907915
pass
908916

909917
@overload
910-
def _get_space(self, *, layout_key: str, type_: Literal["text"]) -> TextSpace:
918+
def get_space(self, *, layout_key: str, type_: Literal["text"]) -> TextSpace:
911919
pass
912920

913921
@overload
914-
def _get_space(self, *, layout_key: str, type_: Literal["html"]) -> HTMLSpace:
922+
def get_space(self, *, layout_key: str, type_: Literal["html"]) -> HTMLSpace:
915923
pass
916924

917925
@overload
918-
def _get_space(self, *, layout_key: str, type_: Literal["medical_file"]) -> MedicalFileSpace:
926+
def get_space(self, *, layout_key: str, type_: Literal["medical_file"]) -> MedicalFileSpace:
919927
pass
920928

921929
@overload
922-
def _get_space(self, *, layout_key: str, type_: Literal["medical_stack"]) -> MedicalStackSpace:
930+
def get_space(self, *, layout_key: str, type_: Literal["medical_stack"]) -> MedicalStackSpace:
923931
pass
924932

925933
@overload
926-
def _get_space(self, *, layout_key: str, type_: Literal["pdf"]) -> PdfSpace:
934+
def get_space(self, *, layout_key: str, type_: Literal["pdf"]) -> PdfSpace:
927935
pass
928936

929-
def _get_space(
937+
def get_space(
930938
self,
931939
*,
932940
id: Optional[str] = None,
@@ -935,9 +943,6 @@ def _get_space(
935943
) -> Space:
936944
"""Retrieves a single space which matches the specified id and type.
937945
938-
**BETA**: This feature is in beta. The Space API is experimental and may change
939-
in future versions. Use with caution in production environments.
940-
941946
Throws an exception if more than one or no space with the specified id and type is found.
942947
943948
Args:
@@ -2658,47 +2663,47 @@ def _parse_space_labels(
26582663
) -> None:
26592664
for space_id, space_info in spaces_info.items():
26602665
if space_info["space_type"] == SpaceType.VIDEO:
2661-
video_space = self._get_space(id=space_id, type_="video")
2666+
video_space = self.get_space(id=space_id, type_="video")
26622667
video_space._parse_space_dict(
26632668
space_info, object_answers=object_answers, classification_answers=classification_answers
26642669
)
26652670
elif space_info["space_type"] == SpaceType.IMAGE:
2666-
image_space = self._get_space(id=space_id, type_="image")
2671+
image_space = self.get_space(id=space_id, type_="image")
26672672
image_space._parse_space_dict(
26682673
space_info, object_answers=object_answers, classification_answers=classification_answers
26692674
)
26702675
elif space_info["space_type"] == SpaceType.IMAGE_SEQUENCE:
2671-
image_sequence_space = self._get_space(id=space_id, type_="image_sequence")
2676+
image_sequence_space = self.get_space(id=space_id, type_="image_sequence")
26722677
image_sequence_space._parse_space_dict(
26732678
space_info, object_answers=object_answers, classification_answers=classification_answers
26742679
)
26752680
elif space_info["space_type"] == SpaceType.AUDIO:
2676-
audio_space = self._get_space(id=space_id, type_="audio")
2681+
audio_space = self.get_space(id=space_id, type_="audio")
26772682
audio_space._parse_space_dict(
26782683
space_info, object_answers=object_answers, classification_answers=classification_answers
26792684
)
26802685
elif space_info["space_type"] == SpaceType.TEXT:
2681-
text_space = self._get_space(id=space_id, type_="text")
2686+
text_space = self.get_space(id=space_id, type_="text")
26822687
text_space._parse_space_dict(
26832688
space_info, object_answers=object_answers, classification_answers=classification_answers
26842689
)
26852690
elif space_info["space_type"] == SpaceType.HTML:
2686-
html_space = self._get_space(id=space_id, type_="html")
2691+
html_space = self.get_space(id=space_id, type_="html")
26872692
html_space._parse_space_dict(
26882693
space_info, object_answers=object_answers, classification_answers=classification_answers
26892694
)
26902695
elif space_info["space_type"] == SpaceType.MEDICAL_FILE:
2691-
medical_file_space = self._get_space(id=space_id, type_="medical_file")
2696+
medical_file_space = self.get_space(id=space_id, type_="medical_file")
26922697
medical_file_space._parse_space_dict(
26932698
space_info, object_answers=object_answers, classification_answers=classification_answers
26942699
)
26952700
elif space_info["space_type"] == SpaceType.MEDICAL_STACK:
2696-
medical_stack_space = self._get_space(id=space_id, type_="medical_stack")
2701+
medical_stack_space = self.get_space(id=space_id, type_="medical_stack")
26972702
medical_stack_space._parse_space_dict(
26982703
space_info, object_answers=object_answers, classification_answers=classification_answers
26992704
)
27002705
elif space_info["space_type"] == SpaceType.PDF:
2701-
pdf_space = self._get_space(id=space_id, type_="pdf")
2706+
pdf_space = self.get_space(id=space_id, type_="pdf")
27022707
pdf_space._parse_space_dict(
27032708
space_info, object_answers=object_answers, classification_answers=classification_answers
27042709
)
@@ -3011,7 +3016,7 @@ def _add_action_answers(self, label_row_dict: dict):
30113016
if space_id is None:
30123017
raise LabelRowError("Object action does not contain spaceId")
30133018

3014-
space = self._get_space(id=space_id, type_="video")
3019+
space = self.get_space(id=space_id, type_="video")
30153020
space._set_answer_from_list(object_hash, answers_list=[answer_dict])
30163021

30173022
def _create_new_object_instance(self, frame_object_label: FrameObject, frame: int) -> ObjectInstance:

tests/objects/spaces/test_audio_space/test_classifications.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_place_classification_on_audio_space(ontology):
2222
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
2323
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
2424

25-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
25+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
2626

2727
# Act
2828
new_classification_instance = text_classification.create_instance()
@@ -80,7 +80,7 @@ def test_place_classification_where_classification_already_exists(ontology):
8080
# Arrange
8181
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
8282
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
83-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
83+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
8484

8585
classification_instance_1 = text_classification.create_instance()
8686

@@ -101,7 +101,7 @@ def test_place_classification_on_where_classification_of_same_class_already_exis
101101
# Arrange
102102
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
103103
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
104-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
104+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
105105

106106
classification_instance_1 = text_classification.create_instance()
107107
classification_instance_2 = text_classification.create_instance()
@@ -128,7 +128,7 @@ def test_place_classification_replace_overlapping_strategy_exists(ontology):
128128
# Arrange
129129
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
130130
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
131-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
131+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
132132

133133
classification_instance_1 = text_classification.create_instance()
134134
classification_instance_2 = text_classification.create_instance()
@@ -153,7 +153,7 @@ def test_remove_classification_from_audio_space(ontology):
153153
# Arrange
154154
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
155155
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
156-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
156+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
157157

158158
new_classification_instance = text_classification.create_instance()
159159
audio_space_1.put_classification_instance(classification_instance=new_classification_instance)
@@ -180,7 +180,7 @@ def test_get_classification_annotations(ontology):
180180
# Arrange
181181
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
182182
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
183-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
183+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
184184

185185
text_classification_instance = text_classification.create_instance()
186186
checklist_classification_instance = checklist_classification.create_instance()
@@ -228,7 +228,7 @@ def test_get_classification_annotations_with_filter_classifications(ontology):
228228
# Arrange
229229
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
230230
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
231-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
231+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
232232
text_classification_instance = text_classification.create_instance()
233233
checklist_classification_instance = checklist_classification.create_instance()
234234

@@ -288,7 +288,7 @@ def test_get_classification_annotations_from_classification_instance(ontology):
288288
# Arrange
289289
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
290290
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
291-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
291+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
292292
text_classification_instance = text_classification.create_instance()
293293
checklist_classification_instance = checklist_classification.create_instance()
294294

@@ -340,7 +340,7 @@ def test_update_annotation_from_classification_annotation(ontology):
340340
# Arrange
341341
label_row = LabelRowV2(DATA_GROUP_METADATA, Mock(), ontology)
342342
label_row.from_labels_dict(DATA_GROUP_TWO_AUDIO_NO_LABELS)
343-
audio_space_1 = label_row._get_space(id="audio-1-uuid", type_="audio")
343+
audio_space_1 = label_row.get_space(id="audio-1-uuid", type_="audio")
344344
classification_instance_1 = text_classification.create_instance()
345345
classification_instance_1.set_answer("Hi there")
346346

0 commit comments

Comments
 (0)