You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under v1 semantics, a CSR-backed LinearExpression (the result of groupby(...).sum(sparse=True)) carries one-dimensional auxiliary coordinates, e.g. the period/region labels of a multi-key observed=True grouping on the flat group dim, or aux coords on surviving dims. When such an expression is turned into a constraint via Model.add_constraints, the resulting CSRConstraint drops every auxiliary coordinate and keeps only the per-dimension index.
The dense path keeps them, so the sparse and dense results differ in their coordinates. This matters for later sel/where on the constraint by aux label and for the v1 aux-conflict rule, which cannot fire on the constraint side anymore.
Cause: CSRConstraint.from_payload builds the constraint from payload.indexes[d] for d in payload.grid_dims only and never looks at payload.coords (linopy/constraints.py, from_payload). CSRConstraint itself stores only a list of per-dim pd.Index, so there is currently no slot for aux coords to live in.
Note
This issue was written by AI (Claude), based on a limitation found while working on #940.
Version Checks (indicate both or one)
masterbranch of Linopy (with feat(v1): CSR sparse groupby-sum accepts multi-key groupers (#757) #940 applied, which is the first change that puts auxiliary coordinates onto a CSR payload).Issue Description
Under v1 semantics, a CSR-backed
LinearExpression(the result ofgroupby(...).sum(sparse=True)) carries one-dimensional auxiliary coordinates, e.g. theperiod/regionlabels of a multi-keyobserved=Truegrouping on the flatgroupdim, or aux coords on surviving dims. When such an expression is turned into a constraint viaModel.add_constraints, the resultingCSRConstraintdrops every auxiliary coordinate and keeps only the per-dimension index.The dense path keeps them, so the sparse and dense results differ in their coordinates. This matters for later
sel/whereon the constraint by aux label and for the v1 aux-conflict rule, which cannot fire on the constraint side anymore.Cause:
CSRConstraint.from_payloadbuilds the constraint frompayload.indexes[d] for d in payload.grid_dimsonly and never looks atpayload.coords(linopy/constraints.py,from_payload).CSRConstraintitself stores only a list of per-dimpd.Index, so there is currently no slot for aux coords to live in.Reproducible Example
Expected Behavior
c_sparse.coordscontainsperiodandregionon thegroupdim, matching the dense constraint and the sparse expression it was built from.Installed Versions
Details
linopy 0.9.1.post1.dev20+g73e65c22d plus PR #940, Python 3.13, xarray/pandas from
uv sync --extra dev.