codeant-ai-for-open-source[bot] commented on code in PR #37071:
URL: https://github.com/apache/superset/pull/37071#discussion_r2685009673


##########
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:
   **Suggestion:** Large integers from pandas often come as numpy integer 
scalars which are not instances of Python `int`, so `_convert_big_integers` 
won't detect/convert them; detect numeric integral scalars (excluding `bool`) 
and convert them to Python `int` before passing to `_convert_big_integers`. 
[logic error]
   
   **Severity Level:** Minor ⚠️
   ```suggestion
                   # Handle numpy integer scalar types (e.g., numpy.int64) as 
well as Python ints.
                   import numbers
                   if isinstance(val, numbers.Integral) and not isinstance(val, 
bool):
                       # Convert numpy integer scalars to Python int so 
_convert_big_integers can detect large integers.
                       record[key] = _convert_big_integers(int(val))
                   else:
   ```
   <details>
   <summary><b>Why it matters? ⭐ </b></summary>
   
   This is a valid logic bug: numpy integer scalars (e.g., numpy.int64) are not 
instances of Python's int, so the helper _convert_big_integers (which checks 
isinstance(val, int)) will miss them and large integers won't be stringified 
for JS safety.
   The suggested check for numbers.Integral (and conversion to int) fixes the 
problem. Doing the conversion here or updating _convert_big_integers to accept 
numbers.Integral would both be fine.
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/dataframe.py
   **Line:** 63:63
   **Comment:**
        *Logic Error: Large integers from pandas often come as numpy integer 
scalars which are not instances of Python `int`, so `_convert_big_integers` 
won't detect/convert them; detect numeric integral scalars (excluding `bool`) 
and convert them to Python `int` before passing to `_convert_big_integers`.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   ```
   </details>



-- 
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