reynoldmorel commented on code in PR #37071:
URL: https://github.com/apache/superset/pull/37071#discussion_r2700485850


##########
tests/unit_tests/dataframe_test.py:
##########
@@ -203,3 +203,91 @@ def test_max_pandas_timestamp(input_, expected) -> None:
     df = results.to_pandas_df()
 
     assert df_to_records(df) == expected
+
+
+def test_df_to_records_with_nan_from_division_by_zero() -> None:
+    """Test that NaN values from division by zero are converted to None."""
+    import numpy as np
+
+    from superset.db_engine_specs import BaseEngineSpec
+    from superset.result_set import SupersetResultSet

Review Comment:
   Is it possible to move this to the top of the file? that way we could avoid 
import duplication?
   
   If this is pattern we are following from previous tests, would be good to 
know if there is any reason why we are doing this, just for context. 



##########
superset/dataframe.py:
##########
@@ -52,6 +55,11 @@ def df_to_records(dframe: pd.DataFrame) -> list[dict[str, 
Any]]:
 
     for record in records:
         for key in record:
-            record[key] = _convert_big_integers(record[key])
+            val = record[key]
+            # Convert NaN/NA values to None for JSON compatibility
+            if pd.isna(val):
+                record[key] = None
+            else:
+                record[key] = _convert_big_integers(val)

Review Comment:
   nit:
   ```
   record[key] = None if pd.isna(record[key]) else 
_convert_big_integers(record[key])
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to