5
5
from tqdm import tqdm
6
6
from concurrent .futures import ThreadPoolExecutor , as_completed
7
7
8
- def create_data_row_upload_dict (table :dict ,
8
+ def create_data_row_upload_dict (client : labelboxClient , table :dict ,
9
9
row_data_col :str , global_key_col :str , external_id_col :str , dataset_id_col :str ,
10
10
dataset_id :str , metadata_index :dict , attachment_index :dict ,
11
11
divider :str , verbose :bool , extra_client :bool = None ):
12
12
""" Multithreads over a Pandas DataFrame, calling create_data_rows() on each row to return an upload dictionary
13
13
Args:
14
+ client : Required (labelbox.client.Client) - Labelbox Client object
14
15
table : Required (dict) - Pandas DataFrame as dict with df.to_dict("records")
15
16
row_data_col : Required (str) - Column containing asset URL or raw text
16
17
global_key_col : Required (str) - Column name containing the data row global key - defaults to row data
@@ -33,8 +34,8 @@ def create_data_row_upload_dict(table:dict,
33
34
unique_global_key_count = len (list (set ([str (row_dict [global_key_col ]) for row_dict in df_dict ])))
34
35
if table_length != unique_global_key_count :
35
36
print (f"Warning: Your global key column is not unique - upload will resume, only uploading 1 data row per unique global key" )
36
- metadata_schema_to_name_key = labelbase .metadata .get_metadata_schema_to_name_key (client = lb_client , lb_mdo = False , divider = divider , invert = False )
37
- metadata_name_key_to_schema = labelbase .metadata .get_metadata_schema_to_name_key (client = lb_client , lb_mdo = False , divider = divider , invert = True )
37
+ metadata_schema_to_name_key = labelbase .metadata .get_metadata_schema_to_name_key (client = client , lb_mdo = False , divider = divider , invert = False )
38
+ metadata_name_key_to_schema = labelbase .metadata .get_metadata_schema_to_name_key (client = client , lb_mdo = False , divider = divider , invert = True )
38
39
if dataset_id :
39
40
dataset_to_global_key_to_upload_dict = {dataset_id : {}}
40
41
else :
@@ -46,7 +47,7 @@ def create_data_row_upload_dict(table:dict,
46
47
print (f'Submitting data rows...' )
47
48
for index , row_dict in tqdm (df_dict ):
48
49
futures .append (exc .submit (
49
- create_data_rows , row_dict , metadata_name_key_to_schema , metadata_schema_to_name_key ,
50
+ create_data_rows , client , row_dict , metadata_name_key_to_schema , metadata_schema_to_name_key ,
50
51
row_data_col , global_key_col , external_id_col , dataset_id_col ,
51
52
dataset_id , metadata_index , attachment_index , divider
52
53
))
@@ -63,7 +64,7 @@ def create_data_row_upload_dict(table:dict,
63
64
else :
64
65
for index , row in table .iterrows ():
65
66
futures .append (exc .submit (
66
- create_data_rows , row_dict , metadata_name_key_to_schema , metadata_schema_to_name_key ,
67
+ create_data_rows , client , row_dict , metadata_name_key_to_schema , metadata_schema_to_name_key ,
67
68
row_data_col , global_key_col , external_id_col , dataset_id_col ,
68
69
dataset_id , metadata_index , attachment_index , divider
69
70
))
@@ -80,13 +81,14 @@ def create_data_row_upload_dict(table:dict,
80
81
print (f'Generated upload list' )
81
82
return global_key_to_upload_dict , errors
82
83
83
- def create_data_rows (row_dict :dict ,
84
+ def create_data_rows (client : labelboxClient , row_dict :dict ,
84
85
metadata_name_key_to_schema :dict , metadata_schema_to_name_key :dict ,
85
86
row_data_col :str , global_key_col :str , external_id_col :str , dataset_id_col :str ,
86
87
metadata_index :str , metadata_index :dict , attachment_index :dict ,
87
88
divider :str ):
88
89
""" Function to-be-multithreaded to create data row dictionaries from a Pandas DataFrame
89
90
Args:
91
+ client : Required (labelbox.client.Client) - Labelbox Client object
90
92
row_dict : Required (dict) - Dictionary where {key=column_name : value=row_value}
91
93
metadata_name_key_to_schema : Required (dict) - Dictionary where {key=metadata_field_name_key : value=metadata_schema_id}
92
94
metadata_schema_to_name_key : Required (dict) - Inverse of metadata_name_key_to_schema
0 commit comments