fix(v1): warn on legacy multi-key groupby MultiIndex; suggest reset_index#840
Merged
FBumann merged 1 commit intoJul 16, 2026
Merged
Conversation
…ndex
Transition-surface audit (working through open-items.md) found one silent
legacy->v1 divergence: `groupby([names]).sum(observed=True)` mints a stacked
`group` MultiIndex under legacy (v1 returns a flat dim + aux coords) but emitted
no warning — only DataFrame groupers did. A legacy model consuming
`.sel(group=(...))` would break under v1 with no deprecation notice.
- _restore_multikey_index: warn whenever legacy keeps a *surviving* group
MultiIndex (drop the DataFrame-only `user_facing` gate); reword the message.
- The warning now offers a robust migration: `.reset_index('group')` yields
exactly the v1 flat result (pinned by assert_linequal from the same expr).
- Tests: namelist+observed warn/flat, the reset_index->v1 equivalence; scope
test_observed_silences_blowup_warning to the blowup warning.
- open-items.md records the audit; no other silent fork site found.
Full suite green (7840 passed); ruff/mypy clean (pre-existing solvers.py ignore
aside).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
The following was generated by AI.
Found by working through
open-items.md— the transition-surface completeness audit (Stage 1: every v1 behaviour-change must warn under legacy, the "no silent change" guarantee).Audit
Probed every convention §'s legacy→v1 divergence under legacy and checked a
LinopySemanticsWarningfires: §5 user-NaN (+/*), §6 masked variable through every operator + comparison, §8 set-mismatch / reorder (const, merge, coeff, rhs<=/>=/==), §11 aux-coord conflict, §12 RHS NaN, #803 MultiIndex construction, unlabeled ambiguous pairing, multi-key groupby. All warned except one.The gap
groupby([names]).sum(observed=True)mints a stackedgroupMultiIndex under legacy (v1 returns a flatgroupdim + key aux coords) but emitted no warning — only the DataFrame-grouper spelling of the same operation warned:observedgroupby(df)groupby([names])Falsegroupby([names])TrueSo a legacy model doing
groupby(["country","carrier"]).sum(observed=True)and consuming.sel(group=(...))would break under v1 with no deprecation notice — exactly the PyPSA-Eur CCL pattern.Fix
_restore_multikey_indexgated the warning onuser_facing(DataFrame groupers only). The correct condition is "legacy keeps a survivinggroupMultiIndex" —stacked_survives and not is_v1(), which the code already reaches only under legacy. Dropped theuser_facingparameter; reworded the message ("multi-key groupby", not "frame grouper").The warning now hands the user a robust one-line migration.
.reset_index("group")on the legacy MI result yields exactly the v1 flatgroupdim + aux coords — verified byassert_linequal(legacy_mi.reset_index("group"), v1_flat)built from the same expression. The message includes it as aConvert:line.Tests: namelist+
observedwarn/flat, thereset_index → v1migration equivalence, and scopedtest_observed_silences_blowup_warningto the blowup warning specifically (it had used a blanketsimplefilter("error")).open-items.mdrecords the audit and that no other silent fork site remains.Full suite green; ruff/mypy clean.