Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit ba360fa

Browse files
Update data_rows.py
1 parent 0d92c48 commit ba360fa

File tree

1 file changed

+32
-42
lines changed

1 file changed

+32
-42
lines changed

labelpandas/data_rows.py

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def create_data_row_upload_dict(client:labelboxClient, table: pandas.core.frame.
6666
futures = []
6767
if verbose:
6868
print(f'Submitting data rows...')
69-
for index, row_dict in tqdm(df_dict):
69+
for row_dict in tqdm(df_dict):
7070
futures.append(exc.submit(
7171
create_data_rows, client, row_dict, metadata_name_key_to_schema, metadata_schema_to_name_key,
7272
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.
7575
print(f'Processing data rows...')
7676
for f in tqdm(as_completed(futures)):
7777
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})
8582
else:
86-
for index, row in table.iterrows():
83+
for row_dict in tqdm(df_dict):
8784
futures.append(exc.submit(
8885
create_data_rows, client, row_dict, metadata_name_key_to_schema, metadata_schema_to_name_key,
8986
row_data_col, global_key_col, external_id_col, dataset_id_col,
9087
dataset_id, metadata_index, attachment_index, divider
9188
))
9289
for f in as_completed(futures):
9390
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})
10195
if verbose:
10296
print(f'Generated upload list')
103-
return global_key_to_upload_dict, errors
97+
return global_key_to_upload_dict
10498

10599
def create_data_rows(client:labelboxClient, row_dict:dict,
106100
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,
126120
- "error" - If there's value in the "error" key, the script will scip it on upload and return the error at the end
127121
- "data_row" - Dictionary with "global_key" "external_id" "row_data" and "metadata_fields" keys in the proper format to-be-uploaded
128122
"""
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]})
154144
return return_value

0 commit comments

Comments
 (0)