fix(dataframe): handle arrays in NA check for JSON data preservation

pd.isna() raises ValueError when called on arrays (lists/dicts from JSON).
Use a helper function that catches this exception and returns False for
array values.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2026-02-22 20:19:25 -08:00
parent 884681fa13
commit 4aac11a8d7

View File

@@ -37,6 +37,22 @@ def _convert_big_integers(val: Any) -> Any:
return str(val) if isinstance(val, int) and abs(val) > JS_MAX_INTEGER else val
def _is_na(val: Any) -> bool:
"""
Check if a value is NA/NaN for scalar values only.
pd.isna() raises ValueError for arrays/lists, so we catch that case.
:param val: the value to check
:returns: True if the value is NA/NaN, False otherwise
"""
try:
return bool(pd.isna(val))
except ValueError:
# pd.isna raises ValueError for arrays (e.g., lists, dicts from JSON)
return False
def df_to_records(dframe: pd.DataFrame) -> list[dict[str, Any]]:
"""
Convert a DataFrame to a set of records.
@@ -56,7 +72,7 @@ def df_to_records(dframe: pd.DataFrame) -> list[dict[str, Any]]:
for record in records:
for key in record:
record[key] = (
None if pd.isna(record[key]) else _convert_big_integers(record[key])
None if _is_na(record[key]) else _convert_big_integers(record[key])
)
return records