@@ -66,7 +66,7 @@ def create_data_row_upload_dict(client:labelboxClient, table: pandas.core.frame.
66
66
futures = []
67
67
if verbose :
68
68
print (f'Submitting data rows...' )
69
- for index , row_dict in tqdm (df_dict ):
69
+ for row_dict in tqdm (df_dict ):
70
70
futures .append (exc .submit (
71
71
create_data_rows , client , row_dict , metadata_name_key_to_schema , metadata_schema_to_name_key ,
72
72
row_data_col , global_key_col , external_id_col , dataset_id_col ,
@@ -75,32 +75,26 @@ def create_data_row_upload_dict(client:labelboxClient, table: pandas.core.frame.
75
75
print (f'Processing data rows...' )
76
76
for f in tqdm (as_completed (futures )):
77
77
res = f .result ()
78
- if res ['error' ]:
79
- errors .append (res )
80
- else :
81
- id = str (list (res .keys ()))[0 ]
82
- data_row_dict = res ["res" ][id ]
83
- global_key = str (data_row_dict ["global_key" ])
84
- dataset_to_global_key_to_upload_dict [id ].update ({global_key :data_row_dict })
78
+ id = str (list (res .keys ()))[0 ]
79
+ data_row_dict = res [id ]
80
+ global_key = str (data_row_dict ["global_key" ])
81
+ dataset_to_global_key_to_upload_dict [id ].update ({global_key :data_row_dict })
85
82
else :
86
- for index , row in table . iterrows ( ):
83
+ for row_dict in tqdm ( df_dict ):
87
84
futures .append (exc .submit (
88
85
create_data_rows , client , row_dict , metadata_name_key_to_schema , metadata_schema_to_name_key ,
89
86
row_data_col , global_key_col , external_id_col , dataset_id_col ,
90
87
dataset_id , metadata_index , attachment_index , divider
91
88
))
92
89
for f in as_completed (futures ):
93
90
res = f .result ()
94
- if res ['error' ]:
95
- errors .append (res )
96
- else :
97
- id = str (list (res .keys ()))[0 ]
98
- data_row_dict = res ["res" ][id ]
99
- global_key = str (data_row_dict ["global_key" ])
100
- dataset_to_global_key_to_upload_dict [id ].update ({global_key :data_row_dict })
91
+ id = str (list (res .keys ()))[0 ]
92
+ data_row_dict = res [id ]
93
+ global_key = str (data_row_dict ["global_key" ])
94
+ dataset_to_global_key_to_upload_dict [id ].update ({global_key :data_row_dict })
101
95
if verbose :
102
96
print (f'Generated upload list' )
103
- return global_key_to_upload_dict , errors
97
+ return global_key_to_upload_dict
104
98
105
99
def create_data_rows (client :labelboxClient , row_dict :dict ,
106
100
metadata_name_key_to_schema :dict , metadata_schema_to_name_key :dict ,
@@ -126,29 +120,25 @@ def create_data_rows(client:labelboxClient, row_dict:dict,
126
120
- "error" - If there's value in the "error" key, the script will scip it on upload and return the error at the end
127
121
- "data_row" - Dictionary with "global_key" "external_id" "row_data" and "metadata_fields" keys in the proper format to-be-uploaded
128
122
"""
129
- return_value = {"error" : None , "res" : {}}
130
- try :
131
- id = dataset_id if dataset_id else row_dict ["dataset_id_col" ]
132
- return_value ["res" ] = {id : {}}
133
- return_value ["res" ][id ]["row_data" ] = str (row_dict [row_data_col ])
134
- return_value ["res" ][id ]["global_key" ] = str (row_dict [global_key_col ])
135
- return_value ["res" ][id ]["external_id" ] = str (row_dict [external_id_col ])
136
- metadata_fields = [{"schema_id" : metadata_name_key_to_schema ['lb_integration_source' ], "value" : "Pandas" }]
137
- if metadata_index :
138
- for metadata_field_name in metadata_index .keys ():
139
- input_metadata = labelbase .metadata .process_metadata_value (
140
- client = client , metadata_value = row_dict [metadata_field_name ], metadata_type = metadata_index [metadata_field_name ],
141
- parent_name = metadata_field_name , metadata_name_key_to_schema = metadata_name_key_to_schema , divider = divider
142
- )
143
- if input_metadata :
144
- metadata_fields .append ({"schema_id" : metadata_name_key_to_schema [metadata_field_name ], "value" : input_metadata })
145
- else :
146
- continue
147
- return_value ["res" ][id ]["metadata_fields" ] = metadata_fields
148
- if attachment_index :
149
- return_value ["res" ][id ]["attachments" ] = []
150
- for column_name in attachment_index :
151
- return_value ["res" ][id ]['attachments' ].append ({"type" : attachment_index [column_name ], "value" : row_dict [column_name ]})
152
- except Exception as e :
153
- return_value ["error" ] = e
123
+ id = dataset_id if dataset_id else row_dict ["dataset_id_col" ]
124
+ return_value = {id : {}}
125
+ return_value [id ]["row_data" ] = str (row_dict [row_data_col ])
126
+ return_value [id ]["global_key" ] = str (row_dict [global_key_col ])
127
+ return_value [id ]["external_id" ] = str (row_dict [external_id_col ])
128
+ metadata_fields = [{"schema_id" : metadata_name_key_to_schema ['lb_integration_source' ], "value" : "Pandas" }]
129
+ if metadata_index :
130
+ for metadata_field_name in metadata_index .keys ():
131
+ input_metadata = labelbase .metadata .process_metadata_value (
132
+ client = client , metadata_value = row_dict [metadata_field_name ], metadata_type = metadata_index [metadata_field_name ],
133
+ parent_name = metadata_field_name , metadata_name_key_to_schema = metadata_name_key_to_schema , divider = divider
134
+ )
135
+ if input_metadata :
136
+ metadata_fields .append ({"schema_id" : metadata_name_key_to_schema [metadata_field_name ], "value" : input_metadata })
137
+ else :
138
+ continue
139
+ return_value [id ]["metadata_fields" ] = metadata_fields
140
+ if attachment_index :
141
+ return_value [id ]["attachments" ] = []
142
+ for column_name in attachment_index :
143
+ return_value [id ]['attachments' ].append ({"type" : attachment_index [column_name ], "value" : row_dict [column_name ]})
154
144
return return_value
0 commit comments