Skip to content

Commit e7dd018

Browse files
authored
[PLT-0] Add in tear down helper to integration test and slightly optimized relationship code (#1920)
1 parent f95e611 commit e7dd018

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

libs/labelbox/src/labelbox/data/serialization/ndjson/label.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ def from_common(
6565
cls, data: LabelCollection
6666
) -> Generator["NDLabel", None, None]:
6767
for label in data:
68-
if all(
69-
isinstance(model, RelationshipAnnotation)
70-
for model in label.annotations
71-
):
72-
yield from cls._create_relationship_annotations(label)
68+
yield from cls._create_relationship_annotations(label)
7369
yield from cls._create_non_video_annotations(label)
7470
yield from cls._create_video_annotations(label)
7571

@@ -194,25 +190,22 @@ def _create_non_video_annotations(cls, label: Label):
194190
f"Unable to convert object to MAL format. `{type(getattr(annotation, 'value',annotation))}`"
195191
)
196192

193+
@classmethod
197194
def _create_relationship_annotations(cls, label: Label):
198-
relationship_annotations = [
199-
annotation
200-
for annotation in label.annotations
201-
if isinstance(annotation, RelationshipAnnotation)
202-
]
203-
for relationship_annotation in relationship_annotations:
204-
uuid1 = uuid4()
205-
uuid2 = uuid4()
206-
source = copy.copy(relationship_annotation.value.source)
207-
target = copy.copy(relationship_annotation.value.target)
208-
if not isinstance(source, ObjectAnnotation) or not isinstance(
209-
target, ObjectAnnotation
210-
):
211-
raise TypeError(
212-
f"Unable to create relationship with non ObjectAnnotations. `Source: {type(source)} Target: {type(target)}`"
213-
)
214-
if not source._uuid:
215-
source._uuid = uuid1
216-
if not target._uuid:
217-
target._uuid = uuid2
218-
yield relationship_annotation
195+
for annotation in label.annotations:
196+
if isinstance(annotation, RelationshipAnnotation):
197+
uuid1 = uuid4()
198+
uuid2 = uuid4()
199+
source = copy.copy(annotation.value.source)
200+
target = copy.copy(annotation.value.target)
201+
if not isinstance(source, ObjectAnnotation) or not isinstance(
202+
target, ObjectAnnotation
203+
):
204+
raise TypeError(
205+
f"Unable to create relationship with non ObjectAnnotations. `Source: {type(source)} Target: {type(target)}`"
206+
)
207+
if not source._uuid:
208+
source._uuid = uuid1
209+
if not target._uuid:
210+
target._uuid = uuid2
211+
yield NDRelationship.from_common(annotation, label.data)

libs/labelbox/tests/data/annotation_import/test_relationships.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def configured_project(
145145
rand_gen,
146146
data_row_json_by_media_type,
147147
normalized_ontology_by_media_type_relationship,
148+
teardown_helpers,
148149
):
149150
"""Configure project for test. Request.param will contain the media type if not present will use Image MediaType. The project will have 10 data rows."""
150151

@@ -186,6 +187,10 @@ def configured_project(
186187
project.global_keys = global_keys
187188

188189
yield project
190+
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)
191+
192+
if dataset:
193+
dataset.delete()
189194

190195

191196
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)