@@ -180,6 +180,51 @@ def test_import_data_types(
180180 data_row .delete ()
181181
182182
183+ def test_import_data_types_by_global_key (
184+ client ,
185+ configured_project ,
186+ initial_dataset ,
187+ rand_gen ,
188+ data_row_json_by_data_type ,
189+ annotations_by_data_type ,
190+ ):
191+
192+ project = configured_project
193+ project_id = project .uid
194+ dataset = initial_dataset
195+ data_type_class = ImageData
196+ set_project_media_type_from_data_type (project , data_type_class )
197+
198+ data_row_ndjson = data_row_json_by_data_type ['image' ]
199+ data_row_ndjson ['global_key' ] = str (uuid .uuid4 ())
200+ data_row = create_data_row_for_project (project , dataset , data_row_ndjson ,
201+ rand_gen (str ))
202+
203+ annotations_ndjson = annotations_by_data_type ['image' ]
204+ annotations_list = [
205+ label .annotations
206+ for label in NDJsonConverter .deserialize (annotations_ndjson )
207+ ]
208+ labels = [
209+ lb_types .Label (data = data_type_class (global_key = data_row .global_key ),
210+ annotations = annotations )
211+ for annotations in annotations_list
212+ ]
213+
214+ label_import = lb .LabelImport .create_from_objects (client , project_id ,
215+ f'test-import-image' ,
216+ labels )
217+ label_import .wait_until_done ()
218+
219+ assert label_import .state == AnnotationImportState .FINISHED
220+ assert len (label_import .errors ) == 0
221+ exported_labels = project .export_labels (download = True )
222+ objects = exported_labels [0 ]['Label' ]['objects' ]
223+ classifications = exported_labels [0 ]['Label' ]['classifications' ]
224+ assert len (objects ) + len (classifications ) == len (labels )
225+ data_row .delete ()
226+
227+
183228def validate_iso_format (date_string : str ):
184229 parsed_t = datetime .datetime .fromisoformat (
185230 date_string ) #this will blow up if the string is not in iso format
@@ -321,6 +366,17 @@ def one_datarow(client, rand_gen, data_row_json_by_data_type, data_type):
321366 dataset .delete ()
322367
323368
369+ @pytest .fixture
370+ def one_datarow_global_key (client , rand_gen , data_row_json_by_data_type ):
371+ dataset = client .create_dataset (name = rand_gen (str ))
372+ data_row_json = data_row_json_by_data_type ['video' ]
373+ data_row = dataset .create_data_row (data_row_json )
374+
375+ yield data_row
376+
377+ dataset .delete ()
378+
379+
324380@pytest .mark .parametrize ('data_type, data_class, annotations' , test_params )
325381def test_import_mal_annotations (client , configured_project_with_one_data_row ,
326382 data_type , data_class , annotations , rand_gen ,
@@ -348,3 +404,33 @@ def test_import_mal_annotations(client, configured_project_with_one_data_row,
348404
349405 assert import_annotations .errors == []
350406 # MAL Labels cannot be exported and compared to input labels
407+
408+
409+ def test_import_mal_annotations_global_key (client ,
410+ configured_project_with_one_data_row ,
411+ rand_gen , one_datarow_global_key ):
412+ data_class = lb_types .VideoData
413+ data_row = one_datarow_global_key
414+ annotations = [video_mask_annotation ]
415+ set_project_media_type_from_data_type (configured_project_with_one_data_row ,
416+ data_class )
417+
418+ configured_project_with_one_data_row .create_batch (
419+ rand_gen (str ),
420+ [data_row .uid ],
421+ )
422+
423+ labels = [
424+ lb_types .Label (data = data_class (global_key = data_row .global_key ),
425+ annotations = annotations )
426+ ]
427+
428+ import_annotations = lb .MALPredictionImport .create_from_objects (
429+ client = client ,
430+ project_id = configured_project_with_one_data_row .uid ,
431+ name = f"import { str (uuid .uuid4 ())} " ,
432+ predictions = labels )
433+ import_annotations .wait_until_done ()
434+
435+ assert import_annotations .errors == []
436+ # MAL Labels cannot be exported and compared to input labels
0 commit comments