5
5
from tqdm .autonotebook import tqdm
6
6
import math
7
7
8
- def create_upload_dict (df :pandas .core .frame .DataFrame , lb_client :Client , base_client :baseClient , row_data_col :str ,
8
+ def create_upload_dict (table :pandas .core .frame .DataFrame , lb_client :Client , base_client :baseClient , row_data_col :str ,
9
9
global_key_col :str = "" , external_id_col :str = "" , metadata_index :dict = {}, local_files :bool = False ,
10
10
divider :str = "///" , verbose = False ):
11
11
""" Multithreads over a Pandas DataFrame, calling create_data_rows() on each row to return an upload dictionary
12
12
Args:
13
- df : Required (pandas.core.frame.DataFrame) - Pandas DataFrame
13
+ table : Required (pandas.core.frame.DataFrame) - Pandas DataFrame
14
14
lb_client : Required (labelbox.client.Client) - Labelbox Client object
15
15
base_client : Required (labelbase.client.Client) - Labelbase Client object
16
16
row_data_col : Required (str) - Column containing asset URL or file path
@@ -29,7 +29,7 @@ def create_upload_dict(df:pandas.core.frame.DataFrame, lb_client:Client, base_cl
29
29
- errors - List of dictionaries containing conversion error information; see connector.create_data_rows() for more information
30
30
"""
31
31
if verbose :
32
- print (f'Creating upload list - { len (df )} rows in Pandas DataFrame' )
32
+ print (f'Creating upload list - { len (table )} rows in Pandas DataFrame' )
33
33
global_key_col = global_key_col if global_key_col else row_data_col
34
34
external_id_col = external_id_col if external_id_col else global_key_col
35
35
metadata_schema_to_name_key = base_client .get_metadata_schema_to_name_key (lb_mdo = False , divider = divider , invert = False )
@@ -40,7 +40,7 @@ def create_upload_dict(df:pandas.core.frame.DataFrame, lb_client:Client, base_cl
40
40
futures = []
41
41
if verbose :
42
42
print (f'Submitting data rows...' )
43
- for index , row in df .iterrows ():
43
+ for index , row in table .iterrows ():
44
44
futures .append (exc .submit (
45
45
create_data_rows , lb_client , base_client , row , metadata_name_key_to_schema , metadata_schema_to_name_key ,
46
46
row_data_col , global_key_col , external_id_col , metadata_index , local_files , divider
@@ -110,33 +110,33 @@ def create_data_rows(lb_client:Client, base_client:baseClient, row:pandas.core.s
110
110
return_value ["data_row" ]["global_key" ] = str (row [global_key_col ])
111
111
return return_value
112
112
113
- def get_columns_function (df ):
113
+ def get_columns_function (table : pandas . core . frame . DataFrame ):
114
114
"""Grabs all column names from a Pandas DataFrame
115
115
Args:
116
116
df : Required (pandas.core.frame.DataFrame) - Pandas DataFrame
117
117
Returns:
118
118
List of strings corresponding to all column names
119
119
"""
120
- return [col for col in df .columns ]
120
+ return [col for col in table .columns ]
121
121
122
- def get_unique_values_function (df , column_name :str ):
122
+ def get_unique_values_function (table : pandas . core . frame . DataFrame , column_name :str ):
123
123
"""Grabs all unique values from a column in a Pandas DataFrame
124
124
Args:
125
125
df : Required (pandas.core.frame.DataFrame) - Pandas DataFrame
126
126
column_name : Required (str) - Column name
127
127
Returns:
128
128
List of strings corresponding to all unique values in a column
129
129
"""
130
- return list (df [column_name ].unique ())
130
+ return list (table [column_name ].unique ())
131
131
132
- def add_column_function (df , column_name :str , default_value = "" ):
132
+ def add_column_function (table : pandas . core . frame . DataFrame , column_name :str , default_value = "" ):
133
133
""" Adds a column of empty values to an existing Pandas DataFrame
134
134
Args:
135
- df : Required (pandas.core.frame.DataFrame) - Pandas DataFrame
135
+ table : Required (pandas.core.frame.DataFrame) - Pandas DataFrame
136
136
column_name : Required (str) - Column name
137
137
default_value : Optional - Value to insert for every row in the newly created column
138
138
Returns:
139
- Your Pandas DataFrame with a new column
139
+ Your table with a new column given the column_name and default_value
140
140
"""
141
- df [column_name ] = default_value
142
- return df
141
+ table [column_name ] = default_value
142
+ return table
0 commit comments