Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-chang committed Mar 22, 2024
1 parent 9de3f1f commit d7d1e8e
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion libs/labelbox/tests/data/annotation_import/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from labelbox.data.annotation_types.data import AudioData, ConversationData, DicomData, DocumentData, HTMLData, ImageData, TextData, LlmPromptCreationData, LlmPromptResponseCreationData, LlmResponseCreationData
from labelbox.data.serialization import NDJsonConverter
from labelbox.schema.annotation_import import AnnotationImportState
from utils import remove_keys_recursive, rename_cuid_key_recursive

DATA_ROW_PROCESSING_WAIT_TIMEOUT_SECONDS = 40
DATA_ROW_PROCESSING_WAIT_SLEEP_INTERNAL_SECONDS = 7
Expand Down Expand Up @@ -56,6 +55,35 @@
], ['video', lb_types.VideoData, [video_mask_annotation]]]


def remove_keys_recursive(d, keys):
for k in keys:
if k in d:
del d[k]
for k, v in d.items():
if isinstance(v, dict):
remove_keys_recursive(v, keys)
elif isinstance(v, list):
for i in v:
if isinstance(i, dict):
remove_keys_recursive(i, keys)


# NOTE this uses quite a primitive check for cuids but I do not think it is worth coming up with a better one
# Also this function is NOT written with performance in mind, good for small to mid size dicts like we have in our test
def rename_cuid_key_recursive(d):
new_key = '<cuid>'
for k in list(d.keys()):
if len(k) == 25 and not k.isalpha(): #primitive check for cuid
d[new_key] = d.pop(k)
for k, v in d.items():
if isinstance(v, dict):
rename_cuid_key_recursive(v)
elif isinstance(v, list):
for i in v:
if isinstance(i, dict):
rename_cuid_key_recursive(i)


def get_annotation_comparison_dicts_from_labels(labels):
labels_ndjson = list(NDJsonConverter.serialize(labels))
for annotation in labels_ndjson:
Expand Down

0 comments on commit d7d1e8e

Please sign in to comment.