6
6
import math
7
7
8
8
def create_upload_dict (df :pandas .core .frame .DataFrame , lb_client :Client , base_client :baseClient , row_data_col :str ,
9
- global_key_col :str = "" , external_id_col :str = "" , metadata_index :dict = {}, local_files :bool = False , divider :str = "///" , verbose = False ):
9
+ global_key_col :str = "" , external_id_col :str = "" , metadata_index :dict = {}, local_files :bool = False ,
10
+ divider :str = "///" , verbose = False ):
10
11
""" Multithreads over a Pandas DataFrame, calling create_data_rows() on each row to return an upload dictionary
11
12
Args:
12
13
df : Required (pandas.core.frame.DataFrame) - Pandas DataFrame
@@ -16,9 +17,12 @@ def create_upload_dict(df:pandas.core.frame.DataFrame, lb_client:Client, base_cl
16
17
global_key_col : Optional (str) - Column name containing the data row global key - defaults to row data
17
18
external_id_col : Optional (str) - Column name containing the data row external ID - defaults to global key
18
19
metadata_index : Optional (dict) - Dictionary where {key=column_name : value=metadata_type}
19
- local_files : Optional (bool) - If True, will create urls for local files; if False, uploads `row_data_col` as urls
20
- divider : Optional (str) - String delimiter for all name keys generated
21
- verbose : Optional (bool) - If True, prints information about code execution
20
+ metadata_type must be either "enum", "string", "datetime" or "number"
21
+ local_files : Optional (bool) - Determines how to handle row_data_col values
22
+ If True, treats row_data_col values as file paths uploads the local files to Labelbox
23
+ If False, treats row_data_col values as urls (assuming delegated access is set up)
24
+ divider : Optional (str) - String delimiter for all name keys generated for parent/child schemas
25
+ verbose : Optional (bool) - If True, prints details about code execution; if False, prints minimal information
22
26
Returns:
23
27
Two values:
24
28
- global_key_to_upload_dict - Dictionary where {key=global_key : value=data row dictionary in upload format}
@@ -62,7 +66,7 @@ def create_upload_dict(df:pandas.core.frame.DataFrame, lb_client:Client, base_cl
62
66
63
67
def create_data_rows (lb_client :Client , base_client :baseClient , row :pandas .core .series .Series ,
64
68
metadata_name_key_to_schema :dict , metadata_schema_to_name_key :dict , row_data_col :str ,
65
- global_key_col :str = "" , external_id_col :str = "" , metadata_index :dict = {} , local_files = False , divider :str = "///" ):
69
+ global_key_col :str , external_id_col :str , metadata_index :dict , local_files : bool , divider :str ):
66
70
""" Function to-be-multithreaded to create data row dictionaries from a Pandas DataFrame
67
71
Args:
68
72
lb_client : Required (labelbox.client.Client) - Labelbox Client object
@@ -71,11 +75,14 @@ def create_data_rows(lb_client:Client, base_client:baseClient, row:pandas.core.s
71
75
metadata_name_key_to_schema : Required (dict) - Dictionary where {key=metadata_field_name_key : value=metadata_schema_id}
72
76
metadata_schema_to_name_key : Required (dict) - Inverse of metadata_name_key_to_schema
73
77
row_data_col : Required (str) - Column containing asset URL or file path
74
- global_key_col : Optional (str) - Column name containing the data row global key
75
- external_id_col : Optional (str) - Column name containing the data row external ID
76
- metadata_index : Optional (dict) - Dictionary where {key=column_name : value=metadata_type}
77
- local_files : Optional (bool) - If True, will create urls for local files; if False, uploads `row_data_col` as urls
78
- divider : Optional (str) - String delimiter for all name keys generated
78
+ global_key_col : Required (str) - Column name containing the data row global key
79
+ external_id_col : Required (str) - Column name containing the data row external ID
80
+ metadata_index : Required (dict) - Dictionary where {key=column_name : value=metadata_type}
81
+ metadata_type must be either "enum", "string", "datetime" or "number"
82
+ local_files : Required (bool) - Determines how to handle row_data_col values
83
+ If True, treats row_data_col values as file paths uploads the local files to Labelbox
84
+ If False, treats row_data_col values as urls (assuming delegated access is set up)
85
+ divider : Required (str) - String delimiter for all name keys generated for parent/child schemas
79
86
Returns:
80
87
A dictionary with "error" and "data_row" keys:
81
88
- "error" - If there's value in the "error" key, the script will scip it on upload and return the error at the end
@@ -126,7 +133,7 @@ def add_column_function(df, column_name:str, default_value=""):
126
133
Args:
127
134
df : Required (pandas.core.frame.DataFrame) - Pandas DataFrame
128
135
column_name : Required (str) - Column name
129
- default_value : Optional - Value to insert into column
136
+ default_value : Optional - Value to insert for every row in the newly created column
130
137
Returns:
131
138
Your Pandas DataFrame with a new column
132
139
"""
0 commit comments