Repository navigation
fix(post-processing): flatten every index level - #45263
AliIbnBotir wants to merge 3 commits into
Conversation
flatten reset only the first level of a MultiIndex, so a pivot with several index columns lost the others when the result was serialized. A single-level index is reset as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
| if reset_index and not isinstance(df.index, pd.RangeIndex): | ||
| df = df.reset_index(level=0) | ||
| # every level of a MultiIndex, e.g. a pivot with several index columns | ||
| df = df.reset_index() |
There was a problem hiding this comment.
Suggestion: When a later index level shares a name with a data column or another level, reset_index() raises ValueError, failing query post-processing.
Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Logic error
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/utils/pandas_postprocessing/flatten.py
**Line:** 105:105
**Comment:**
*Logic Error: When a later index level shares a name with a data column or another level, `reset_index()` raises `ValueError`, failing query post-processing.
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 fixThere was a problem hiding this comment.
Thanks. This collision isn’t new: the previous reset_index(level=0) already raises the same ValueError when level 0 shares a name with a column. This PR applies the same behaviour to every level instead of silently dropping levels 1..n. Happy to add explicit handling if maintainers prefer, but it seems out of scope for this fix.
There was a problem hiding this comment.
✅ Customized review instruction saved!
Instruction:
Do not flag
reset_index()name-collision failures inflatten; level-0 collisions already had this behavior, and extending the reset to all levels is intentional in this change.
Applied to:
superset/utils/pandas_postprocessing/flatten.py
💡 To manage or update this instruction, visit: CodeAnt AI Settings
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #45263 +/- ##
===========================================
+ Coverage 65.62% 84.70% +19.08%
===========================================
Files 3069 3069
Lines 205661 205649 -12
Branches 48336 48335 -1
===========================================
+ Hits 134956 174200 +39244
+ Misses 67624 28156 -39468
- Partials 3081 3293 +212
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
EnxDev
left a comment
There was a problem hiding this comment.
Looks good to me. With a single-level index reset_index() does exactly what reset_index(level=0) did, so the only behavior change is the MultiIndex case from #45261, and the new test pins that down.
The built-in charts all pivot on [xAxisLabel] only, so this really only shows up for API callers that pivot on several index columns. I agree with your read on the name-collision thread: level 0 could already collide the same way, and raising beats quietly dropping columns.
The red check-openapi-spec-drift looks unrelated, nothing here touches the API schema.
SUMMARY
flattenpost-processing reset only the first level of the dataframe index(
df.reset_index(level=0)). After apivotwith two or more index columns, theremaining index levels were never turned back into columns, so they were lost
when the result was serialized.
flattennow resets every index level. Asingle-level index behaves as before.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (backend only)
TESTING INSTRUCTIONS
pytest tests/unit_tests/pandas_postprocessing/test_flatten.pytest_flat_should_reset_every_index_levelpivots on two indexcolumns and checks that both come back as columns after
flatten.ADDITIONAL INFORMATION