Skip to content

fix: freeze constraints with a MultiIndex dimension - #1022

Open
MaykThewessen wants to merge 2 commits into
PyPSA:masterfrom
MaykThewessen:fix/freeze-multiindex
Open

MaykThewessen wants to merge 2 commits into
PyPSA:masterfrom
MaykThewessen:fix/freeze-multiindex

Conversation

@MaykThewessen

@MaykThewessen MaykThewessen commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Note

AI-assisted. Claude wrote the fix and test, and ran the checks listed below. I reviewed the diff.

Changes proposed in this Pull Request

Freezing a constraint over a MultiIndex dimension raised TypeError: Must pass list-like as names. Grid.from_dataset named each index after its dimension with Index.rename, and on a MultiIndex that renames the levels. It now sets the name of a MultiIndex and keeps its level names, through a small _named helper. CSRLinearExpression.from_grouper used the same rename call, so it uses the helper too; that path is only reachable under v1 today, which rejects MultiIndex dims, so it is a consistency change. Found while working on #1021.

Checklist

  • AI-generated content is marked (see AGENTS.md).
  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.
What was checked (AI-generated)
  • New test_model_to_netcdf_with_multiindex_frozen_constraint in test/test_io.py (legacy only, like the existing MultiIndex fixture). It fails on master with the TypeError above and passes with the fix.
  • A frozen MultiIndex constraint solves with HiGHS and gives the same duals as the dense constraint, and the model round-trips through netCDF and writes an LP file.
  • Full test suite, branch vs master: no failures on the branch that master doesn't have. The remaining ones come from the environment (missing oetc extras, HiGHS without SOS).

🤖 Generated with Claude Code

Grid.from_dataset named each index after its dimension with
Index.rename, which on a MultiIndex renames the levels and raises
"Must pass list-like as `names`". Set the name of a MultiIndex instead
and keep its level names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codspeed

codspeed Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 181 skipped benchmarks1


Comparing MaykThewessen:fix/freeze-multiindex (d130c9f) with master (ff5436f)

Open in CodSpeed

Footnotes

  1. 181 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant