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

Commit 21cf3ea

Browse files
Update data_rows.py
1 parent 53cdabe commit 21cf3ea

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

labelpandas/data_rows.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from tqdm import tqdm
66
from concurrent.futures import ThreadPoolExecutor, as_completed
77

8-
def create_data_row_upload_dict(table:dict,
8+
def create_data_row_upload_dict(client:labelboxClient, table:dict,
99
row_data_col:str, global_key_col:str, external_id_col:str, dataset_id_col:str,
1010
dataset_id:str, metadata_index:dict, attachment_index:dict,
1111
divider:str, verbose:bool, extra_client:bool=None):
1212
""" Multithreads over a Pandas DataFrame, calling create_data_rows() on each row to return an upload dictionary
1313
Args:
14+
client : Required (labelbox.client.Client) - Labelbox Client object
1415
table : Required (dict) - Pandas DataFrame as dict with df.to_dict("records")
1516
row_data_col : Required (str) - Column containing asset URL or raw text
1617
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,
3334
unique_global_key_count = len(list(set([str(row_dict[global_key_col]) for row_dict in df_dict])))
3435
if table_length != unique_global_key_count:
3536
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)
3839
if dataset_id:
3940
dataset_to_global_key_to_upload_dict = {dataset_id : {}}
4041
else:
@@ -46,7 +47,7 @@ def create_data_row_upload_dict(table:dict,
4647
print(f'Submitting data rows...')
4748
for index, row_dict in tqdm(df_dict):
4849
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,
5051
row_data_col, global_key_col, external_id_col, dataset_id_col,
5152
dataset_id, metadata_index, attachment_index, divider
5253
))
@@ -63,7 +64,7 @@ def create_data_row_upload_dict(table:dict,
6364
else:
6465
for index, row in table.iterrows():
6566
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,
6768
row_data_col, global_key_col, external_id_col, dataset_id_col,
6869
dataset_id, metadata_index, attachment_index, divider
6970
))
@@ -80,13 +81,14 @@ def create_data_row_upload_dict(table:dict,
8081
print(f'Generated upload list')
8182
return global_key_to_upload_dict, errors
8283

83-
def create_data_rows(row_dict:dict,
84+
def create_data_rows(client:labelboxClient, row_dict:dict,
8485
metadata_name_key_to_schema:dict, metadata_schema_to_name_key:dict,
8586
row_data_col:str, global_key_col:str, external_id_col:str, dataset_id_col:str,
8687
metadata_index:str, metadata_index:dict, attachment_index:dict,
8788
divider:str):
8889
""" Function to-be-multithreaded to create data row dictionaries from a Pandas DataFrame
8990
Args:
91+
client : Required (labelbox.client.Client) - Labelbox Client object
9092
row_dict : Required (dict) - Dictionary where {key=column_name : value=row_value}
9193
metadata_name_key_to_schema : Required (dict) - Dictionary where {key=metadata_field_name_key : value=metadata_schema_id}
9294
metadata_schema_to_name_key : Required (dict) - Inverse of metadata_name_key_to_schema

0 commit comments

Comments
 (0)