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

Commit 87f0129

Browse files
Merge pull request #15 from Labelbox/client-update
Client update
2 parents eb1cf3d + 4a00749 commit 87f0129

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

labelpandas/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def create_data_rows_from_table(
142142
model_id_col=x["model_id_col"], model_id=model_id,
143143
model_run_id_col=x["model_run_id_col"], model_run_id=model_run_id,
144144
metadata_index=x["metadata_index"], attachment_index=x["attachment_index"],
145-
annotation_index=x["annotation_index"], prediction_index=x["prediction_index"], batch_action=actions['batch'],
145+
annotation_index=x["annotation_index"], prediction_index=x["prediction_index"], batch_action=actions["batch"],
146146
create_action=actions["create"], annotate_action=actions["annotate"], prediction_action=actions["predictions"],
147147
upload_method=upload_method, mask_method=mask_method, divider=divider, verbose=verbose
148148
)

labelpandas/uploader.py

+26-11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from labelbase.models import create_model_run_with_name
3131
from labelbase.annotate import create_ndjsons
3232
from concurrent.futures import ThreadPoolExecutor, as_completed
33+
from uuid import uuid4
3334

3435
def create_upload_dict(client:labelboxClient, table: pandas.core.frame.DataFrame, table_dict:dict,
3536
row_data_col:str, global_key_col:str, external_id_col:str,
@@ -186,6 +187,13 @@ def create_upload(row_dict:dict, row_data_col:str, global_key_col:str, external_
186187
"predictions" : [] -- List of predictions for a given data row, if applicable
187188
}
188189
"""
190+
#Remove nan values from dictionary
191+
nan_keys = []
192+
for key in row_dict.keys():
193+
if pandas.isna(row_dict[key]):
194+
nan_keys.append(key)
195+
for key in nan_keys:
196+
del row_dict[key]
189197
# Determine dataset ID
190198
if dataset_id:
191199
datasetId = dataset_id
@@ -214,24 +222,31 @@ def create_upload(row_dict:dict, row_data_col:str, global_key_col:str, external_
214222
modelRunId = ""
215223
# Create a base data row dictionary
216224
data_row = {}
217-
if create_action or batch_action:
225+
if create_action or batch_action:
218226
data_row["row_data"] = row_dict[row_data_col]
219-
data_row["global_key"] = row_dict[global_key_col]
220-
data_row["external_id"] = row_dict[external_id_col]
227+
if len(row_dict[global_key_col]) <= 200:
228+
data_row["global_key"] = row_dict[global_key_col]
229+
else:
230+
if verbose:
231+
print("Global key too long (>200 characters). Replacing with randomly generated global key.")
232+
data_row["global_key"] = str(uuid4())
233+
if external_id_col in row_dict.keys():
234+
data_row["external_id"] = row_dict[external_id_col]
221235
# Create a list of metadata for a data row
222236
metadata_fields = [{"schema_id" : metadata_name_key_to_schema['lb_integration_source'], "value" : "LabelPandas"}]
223237
if metadata_index:
224238
for metadata_field_name in metadata_index.keys():
225239
metadata_type = metadata_index[metadata_field_name]
226240
column_name = f"metadata{divider}{metadata_type}{divider}{metadata_field_name}"
227-
input_metadata = process_metadata_value(
228-
metadata_value=row_dict[column_name], metadata_type=metadata_type,
229-
parent_name=metadata_field_name, metadata_name_key_to_schema=metadata_name_key_to_schema, divider=divider
230-
)
231-
if input_metadata:
232-
metadata_fields.append({"schema_id" : metadata_name_key_to_schema[metadata_field_name], "value" : input_metadata})
233-
else:
234-
continue
241+
if column_name in row_dict.keys():
242+
input_metadata = process_metadata_value(
243+
metadata_value=row_dict[column_name], metadata_type=metadata_type,
244+
parent_name=metadata_field_name, metadata_name_key_to_schema=metadata_name_key_to_schema, divider=divider
245+
)
246+
if input_metadata:
247+
metadata_fields.append({"schema_id" : metadata_name_key_to_schema[metadata_field_name], "value" : input_metadata})
248+
else:
249+
continue
235250
data_row["metadata_fields"] = metadata_fields
236251
# Create a list of attachments for a data row
237252
if attachment_index:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='labelpandas',
8-
version='0.1.38',
8+
version='0.1.39',
99
author='Labelbox',
1010
author_email="raphael@labelbox.com",
1111
description='Labelbox Connector for Pandas',

0 commit comments

Comments
 (0)