mirror of
https://github.com/apache/superset.git
synced 2026-04-26 11:34:27 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user