codeant-ai-for-open-source[bot] commented on code in PR #45018:
URL: https://github.com/apache/superset/pull/45018#discussion_r4192623967
##########
superset/utils/pandas_postprocessing/utils.py:
##########
@@ -238,13 +243,25 @@ def _append_columns(
in `base_df` unchanged.
:return: new DataFrame with combined data from `base_df` and `append_df`
"""
- if all(key == value for key, value in columns.items()):
+ if not columns:
+ # Nothing to combine, but still hand back a new DataFrame so that a
+ # caller which mutates the result does not reach `base_df`.
+ return base_df.copy()
+
+ overwritten = {key: value for key, value in columns.items() if key ==
value}
+ appended = {key: value for key, value in columns.items() if key != value}
+
+ _base_df = base_df
+ if overwritten:
# make sure to return a new DataFrame instead of changing the
`base_df`.
_base_df = base_df.copy()
- _base_df.loc[:, columns.keys()] = append_df
+ _base_df.loc[:, overwritten.keys()] = append_df
+ if not appended:
return _base_df
- append_df = append_df.rename(columns=columns)
- return pd.concat([base_df, append_df], axis="columns")
+ # Select before renaming: `append_df` may carry columns the mapping does
not
+ # ask for, and those must not reach the result.
+ appended_df = append_df.loc[:, appended.keys()].rename(columns=appended)
+ return pd.concat([_base_df, appended_df], axis="columns")
Review Comment:
**Suggestion:** `pd.concat` aligns by index and takes the union, so parsing
an input with a non-RangeIndex can add stray rows from the parsed frame's
RangeIndex.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Logic error`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=96b0d1941daa432795694ab62f14d3c0&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=96b0d1941daa432795694ab62f14d3c0&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/utils.py
**Line:** 264:264
**Comment:**
*Logic Error: `pd.concat` aligns by index and takes the union, so
parsing an input with a non-RangeIndex can add stray rows from the parsed
frame's RangeIndex.
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%2F45018&comment_hash=e23ce0ce57585945ed1ebd0fdba20d7066c9ac7a37df6fd98dabf2cb9a859abb&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45018&comment_hash=e23ce0ce57585945ed1ebd0fdba20d7066c9ac7a37df6fd98dabf2cb9a859abb&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]