Skip to content

fix(spec): an internal grouped sum onto a sparse key no longer warns of a dense grid - #1192

Merged
FabianHofmann merged 2 commits into
masterfrom
fix/spec-grouped-sum-dense-warning
Nov 19, 2026
Merged

FabianHofmann merged 2 commits into
masterfrom
fix/spec-grouped-sum-dense-warning

Conversation

@FabianHofmann

Copy link
Copy Markdown
Collaborator

Note

The following content was generated by AI.

Changes proposed in this Pull Request

Model.from_spec on a sparse model warned that grouping by [<key>, <dim>] makes a dense grid and to pass observed=True. The warning came from linopy itself, not from the user's spec: at read along its own key dimension (_at_by_rows) goes through grouped_sum, which groups the sparse rows and then reindexes onto the full key. The dense grid is the intended result there, and observed=True would break the following reindex(onto).

grouped_sum now ignores this one warning around its internal groupby(...).sum(). A user's own groupby still warns.

Seen in PyPSA (carbon management example, Link × port):

UserWarning: Grouping a LinearExpression by ['Link', 'port'] produces a dense 27,320-cell grid, but only 11,750 of those combinations occur ...

A regression test calls grouped_sum on a sparse and a dense expression with warnings as errors and checks both agree. It fails without the fix.

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.md of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@codspeed

codspeed Bot commented Nov 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 181 skipped benchmarks1


Comparing fix/spec-grouped-sum-dense-warning (acb9bd8) with master (f202b4c)

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. ↩

@FabianHofmann
FabianHofmann merged commit 912a8c9 into master Nov 19, 2026
22 of 23 checks passed
@FabianHofmann
FabianHofmann deleted the fix/spec-grouped-sum-dense-warning branch November 19, 2026 14:25
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