Skip to content

Commit 9b4d961

Browse files
authored
Converts numbered labels to strings (#126)
* Converts numbered labels to strings * Update record_transfer_manager.py * Update record_transfer_manager.py
1 parent 41a6933 commit 9b4d961

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

controller/transfer/record_transfer_manager.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,30 @@ def split_record_data_and_label_data(
266266
label_data = {}
267267
for imported_key, item in data_item.items():
268268
if "__" in imported_key:
269-
if (
270-
item.strip() == ""
271-
): # if a label is only consists of whitespaces or is empty continue
269+
item_str = item
270+
if not isinstance(item, str):
271+
if isinstance(item, float):
272+
# special case since str(float) returns a string with a dot for integers %g is used to perserve . if nessecary but removes otherwise
273+
# this will result in some issues for close large numbers but this shouldn't be used as a label name anyway
274+
item_str = "%g" % (item)
275+
else:
276+
item_str = str(item)
277+
278+
if item_str.strip() == "":
279+
# if a label is only consists of whitespaces or is empty continue
272280
continue
273281

274282
task_name = controller.labeling_task.util.infer_labeling_task_name(
275283
imported_key
276284
)
277-
label_data[task_name] = item
285+
label_data[task_name] = item_str
278286
tasks_data[task_name] = tasks_data.get(task_name) or {
279287
"attribute": controller.transfer.util.infer_attribute(imported_key)
280288
or None,
281289
"labels": [],
282290
}
283-
if item not in tasks_data.get(task_name).get("labels"):
284-
tasks_data.get(task_name).get("labels").append(item)
291+
if item_str not in tasks_data.get(task_name).get("labels"):
292+
tasks_data.get(task_name).get("labels").append(item_str)
285293
else:
286294
record_data[imported_key] = item
287295
records_data.append(record_data)

0 commit comments

Comments
 (0)