Skip to content

[PLT-0] Add in tear down helper to integration test and slightly optimized relationship code #1920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 25, 2024
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
45 changes: 19 additions & 26 deletions libs/labelbox/src/labelbox/data/serialization/ndjson/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ def from_common(
cls, data: LabelCollection
) -> Generator["NDLabel", None, None]:
for label in data:
if all(
isinstance(model, RelationshipAnnotation)
for model in label.annotations
):
yield from cls._create_relationship_annotations(label)
yield from cls._create_relationship_annotations(label)
yield from cls._create_non_video_annotations(label)
yield from cls._create_video_annotations(label)

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

@classmethod
def _create_relationship_annotations(cls, label: Label):
relationship_annotations = [
annotation
for annotation in label.annotations
if isinstance(annotation, RelationshipAnnotation)
]
for relationship_annotation in relationship_annotations:
uuid1 = uuid4()
uuid2 = uuid4()
source = copy.copy(relationship_annotation.value.source)
target = copy.copy(relationship_annotation.value.target)
if not isinstance(source, ObjectAnnotation) or not isinstance(
target, ObjectAnnotation
):
raise TypeError(
f"Unable to create relationship with non ObjectAnnotations. `Source: {type(source)} Target: {type(target)}`"
)
if not source._uuid:
source._uuid = uuid1
if not target._uuid:
target._uuid = uuid2
yield relationship_annotation
for annotation in label.annotations:
if isinstance(annotation, RelationshipAnnotation):
uuid1 = uuid4()
uuid2 = uuid4()
source = copy.copy(annotation.value.source)
target = copy.copy(annotation.value.target)
if not isinstance(source, ObjectAnnotation) or not isinstance(
target, ObjectAnnotation
):
raise TypeError(
f"Unable to create relationship with non ObjectAnnotations. `Source: {type(source)} Target: {type(target)}`"
)
if not source._uuid:
source._uuid = uuid1
if not target._uuid:
target._uuid = uuid2
yield NDRelationship.from_common(annotation, label.data)
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def configured_project(
rand_gen,
data_row_json_by_media_type,
normalized_ontology_by_media_type_relationship,
teardown_helpers,
):
"""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."""

Expand Down Expand Up @@ -186,6 +187,10 @@ def configured_project(
project.global_keys = global_keys

yield project
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)

if dataset:
dataset.delete()


@pytest.mark.parametrize(
Expand Down
Loading