Skip to content

Commit 4db3261

Browse files
authored
Merge pull request #226 from OpenUpSA/elastic-debugging
NaN error
2 parents ddb7b15 + 67f3ab0 commit 4db3261

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

helpers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ def tsv_to_json_pandas(tsv_string, project_id):
565565

566566
field_type = field_schema.get("type")
567567
split_regex = field_schema.get("x-split-regex")
568+
field_format = field_schema.get("format")
568569

569570
# Handle arrays
570571
if field_type == "array":
@@ -574,13 +575,12 @@ def tsv_to_json_pandas(tsv_string, project_id):
574575
elif field_type == "number":
575576
df[column] = df[column].apply(lambda x: convert_to_number(x))
576577

577-
# Handle dates (string with format date)
578-
elif field_type == "string" and field_schema.get("format") == "date":
579-
df[column] = df[column].apply(lambda x: x if x and x.strip() else None)
578+
# Handle dates (string with format date): set None if missing/empty/NaN
579+
elif field_type == "string" and field_format == "date":
580+
df[column] = df[column].apply(lambda x: x if (x is not None and isinstance(x, str) and x.strip()) else None)
580581

581-
# Handle strings
582+
# Handle strings (not date): always use empty string for missing/None/NaN
582583
elif field_type == "string":
583-
# For string fields, always use empty string for missing/None/NaN
584584
df[column] = df[column].apply(lambda x: x if (x is not None and not (isinstance(x, float) and pd.isna(x))) else "")
585585

586586
# Other types: leave as is

0 commit comments

Comments
 (0)