codeant-ai-for-open-source[bot] commented on code in PR #43694:
URL: https://github.com/apache/superset/pull/43694#discussion_r3889949270
##########
superset/utils/pandas_postprocessing/pivot.py:
##########
@@ -299,8 +299,26 @@ def pivot( # pylint: disable=too-many-arguments # noqa:
C901
percent_mode = show_values_as
if columns and column_fill_value:
+ for col in columns:
+ if (
+ isinstance(df[col].dtype, pd.CategoricalDtype)
+ and column_fill_value not in df[col].cat.categories
+ ):
+ df[col] = df[col].cat.add_categories([column_fill_value])
df[columns] = df[columns].fillna(value=column_fill_value)
+ # Fill NULL/NaN values in the index columns with NULL_STRING so that
+ # NULL grouping keys survive as a real "<NULL>" row in the pivot output.
+ # Mirrors the column fill above; pivot_table() drops NaN index rows
+ # regardless of the dropna= setting (dropna only governs the column axis).
+ for col in index:
+ if (
+ isinstance(df[col].dtype, pd.CategoricalDtype)
+ and NULL_STRING not in df[col].cat.categories
+ ):
+ df[col] = df[col].cat.add_categories([NULL_STRING])
+ df[index] = df[index].fillna(value=NULL_STRING)
Review Comment:
**Suggestion:** Filling a datetime index containing `NaT` with the string
`<NULL>` is incompatible with pandas datetime dtype and can raise a runtime
`TypeError`. [type error]
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c786f6d0a99a40bdaebf740f33d8056c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c786f6d0a99a40bdaebf740f33d8056c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/utils/pandas_postprocessing/pivot.py
**Line:** 320:320
**Comment:**
*Type Error: Filling a datetime index containing `NaT` with the string
`<NULL>` is incompatible with pandas datetime dtype and can raise a runtime
`TypeError`.
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.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43694&comment_hash=bc72e24a150d0330978cc8191959e97a36bc5199c3b2b3e9648c16bf70b9e422&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43694&comment_hash=bc72e24a150d0330978cc8191959e97a36bc5199c3b2b3e9648c16bf70b9e422&reaction=dislike'>๐</a>
--
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]