From 4aac11a8d7817fa8a3cca8ff260e57f2df3a680b Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Sun, 22 Feb 2026 20:19:25 -0800 Subject: [PATCH] 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 --- superset/dataframe.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/superset/dataframe.py b/superset/dataframe.py index 0e7cba0bc3c..7ce7a0c425d 100644 --- a/superset/dataframe.py +++ b/superset/dataframe.py @@ -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