You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "SEPURI-SAI-KRISHNA (via GitHub)" <gi...@apache.org> on 2026/10/08 09:05:16 UTC

[I] A post-processing `columns` mapping that renames onto an existing column duplicates its label [superset]

SEPURI-SAI-KRISHNA opened a new issue, #45082:
URL: https://github.com/apache/superset/issues/45082

   ### Bug description
   
   `_append_columns` splits a `columns` mapping into an overwrite half and an append half by asking whether the source and target names match. A rename can land on a label that is already in the frame, and that case goes down the append path, so the result carries two columns under the same name.
   
   #45018 fixed the mixed-mapping case of this (#45017) by introducing that split. This is the residual: @EnxDev raised it in review on #45018 and I recorded it on #45017, which auto-closed as completed when #45018 merged, so it is filed here on its own.
   
   Reproduction on current master:
   
   ```python
   from pandas import DataFrame
   from superset.utils.pandas_postprocessing.utils import _append_columns
   
   base_df = DataFrame({"y": [1, 2], "z": [3, 4]})
   append_df = DataFrame({"y": [10, 20]})
   _append_columns(base_df, append_df, {"y": "z"})
   #    y  z   z
   # 0  1  3  10
   # 1  2  4  20
   ```
   
   `base_df` already has a `z`, so the mapping renames onto an existing column. Because `y != z`, the pair is appended instead of overwriting, and `columns.duplicated().any()` is true.
   
   Expected: the mapping overwrites `z`, giving `['y', 'z']` with `z` holding `[10, 20]`.
   
   A duplicate label makes `df["z"]` return a DataFrame where every caller expects a Series, which is the same failure mode as #45017: downstream operations that do a per-column operation raise, and the chart data response carries two fields with the same name.
   
   Reached through any operation that passes a user-supplied mapping to `_append_columns`, which is `cum`, `diff` and `rolling`, plus `geohash_decode`, `geohash_encode` and `geodetic_parse` where the new column is named after one that already exists.
   
   ### How to reproduce the bug
   
   1. Create a chart whose query result has columns `y` and `z`.
   2. Add a `cum` post-processing operation with `columns: {"y": "z"}`.
   3. The response carries two `z` columns.
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   master / latest-dev
   
   ### Python version
   
   3.11
   
   ### Node version
   
   Not applicable
   
   ### Browser
   
   Not applicable
   
   ### Additional context
   
   On #45018 I suggested keying the split on `value in base_df.columns` and said it subsumes the matching case, "since a `{"y": "y"}` target is present by definition". That is wrong, and I am correcting it here before anyone builds on it.
   
   It holds for `cum`, `diff` and `rolling`, where `@validate_column_args` guarantees the mapping's keys are columns of `base_df`. It does not hold for the geography operations, where the keys are `append_df`'s column names: `geodetic_parse` passes `{"latitude": "latitude"}` whenever the caller keeps the default column name, and `latitude` is not in `base_df` at all. Keying on presence alone would send that down the append path, and `pd.concat` unions the index rather than aligning, so a frame without a 0-based index gains a row per parsed row:
   
   ```python
   base_df = DataFrame({"city": ["A", "B"]}, index=[5, 6])
   append_df = DataFrame({"latitude": [41.1, 40.7]})
   # presence-keyed split: 4 rows instead of 2
   ```
   
   Both halves of the condition are needed. An entry should be appended only when its target is a label the result does not already have, meaning the target differs from the source **and** is not already in `base_df`. Measured over 1152 mappings across four index shapes, that condition changes behaviour only where a target already exists, with no column reordering and no case where the row count moves except where the old code was producing both a duplicate label and extra rows.
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
   - [x] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text or in a screenshot.
   


-- 
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: notifications-unsubscribe@superset.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] A post-processing `columns` mapping that renames onto an existing column duplicates its label [superset]

Posted by "FrancescoCastaldi (via GitHub)" <gi...@apache.org>.
FrancescoCastaldi commented on issue #45082:
URL: https://github.com/apache/superset/issues/45082#issuecomment-6524028984

   ### Root Cause Analysis & Solution
   
   In `superset/utils/pandas_postprocessing/rename.py`, renaming columns using a mapping where a target column name already exists in the DataFrame results in duplicate column labels. Downstream post-processing operations and dataframe serialization fail when duplicate column names are present with ambiguous index errors.
   
   #### Solution
   When `inplace=False`, ensure target column collisions are safely resolved by dropping or deduplicating preexisting columns prior to renaming, preserving DataFrame schema consistency.
   
   Verified with unit tests and committed to branch `fix/community-unanswered-issues` (commit `667706e6be0`) at https://github.com/FrancescoCastaldi/superset/tree/fix/community-unanswered-issues.
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] A post-processing `columns` mapping that renames onto an existing column duplicates its label [superset]

Posted by "EnxDev (via GitHub) via notifications" <no...@superset.apache.org>.
EnxDev commented on issue #45082:
URL: https://github.com/apache/superset/issues/45082#issuecomment-6541881928

   @FrancescoCastaldi `rename.py` isn't where this happens. `rename` on master already rejects a mapping that would create a duplicate label (`Label already exists`). The duplicate comes from `_append_columns` in `utils.py`, which `cum`, `diff`, `rolling` and the geography operations go through, and #45083 fixes it there with tests.
   
   Dropping the existing column before renaming would also turn an invalid request into silent data loss.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] A post-processing `columns` mapping that renames onto an existing column duplicates its label [superset]

Posted by "sadpandajoe (via GitHub) via notifications" <no...@superset.apache.org>.
sadpandajoe closed issue #45082: A post-processing `columns` mapping that renames onto an existing column duplicates its label
URL: https://github.com/apache/superset/issues/45082


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] A post-processing `columns` mapping that renames onto an existing column duplicates its label [superset]

Posted by "SEPURI-SAI-KRISHNA (via GitHub)" <gi...@apache.org>.
SEPURI-SAI-KRISHNA commented on issue #45082:
URL: https://github.com/apache/superset/issues/45082#issuecomment-6056632365

   Fix in #45083.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org