From d7d1e8e2bee641b45b1ca0c87d21df40b1521aff Mon Sep 17 00:00:00 2001 From: Adrian Chang Date: Thu, 21 Mar 2024 23:16:55 -0700 Subject: [PATCH] fix test --- .../data/annotation_import/test_data_types.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/libs/labelbox/tests/data/annotation_import/test_data_types.py b/libs/labelbox/tests/data/annotation_import/test_data_types.py index eaf71e55d5..6a25fac223 100644 --- a/libs/labelbox/tests/data/annotation_import/test_data_types.py +++ b/libs/labelbox/tests/data/annotation_import/test_data_types.py @@ -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 @@ -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 = '' + 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: