Repository navigation
fix: keep auxiliary coordinates of dense containers in netcdf round trip - #1024
Merged
FabianHofmann merged 3 commits intoOct 21, 2026
Merged
Conversation
MaykThewessen
added a commit
to MaykThewessen/linopy
that referenced
this pull request
Oct 8, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
This was referenced Oct 8, 2026
read_netcdf dropped every non-index coordinate except MultiIndex levels to keep out the scalar coordinates of other containers that xarray attaches when selecting one container's data variables. That also dropped the auxiliary coordinates of dense variables, constraints, expressions and parameters, such as the levels on a flat dimension that v1 recommends instead of a MultiIndex. Only drop scalar coordinates owned by another container, matched on the longest prefix since names may contain dashes. Coordinates with dimensions only attach to the container whose dimensions they share. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FabianHofmann
force-pushed
the
fix/netcdf-keep-aux-coords
branch
from
October 20, 2026 07:41
4b5234f to
8901a8f
Compare
FabianHofmann
pushed a commit
to MaykThewessen/linopy
that referenced
this pull request
Oct 20, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ux-coords # Conflicts: # doc/release_notes.rst
FabianHofmann
approved these changes
Oct 21, 2026
FabianHofmann
added a commit
that referenced
this pull request
Oct 21, 2026
* fix: type check with numpy 2.5.4 isscalar stubs (#1031) * fix: type check with numpy 2.5.4 isscalar stubs numpy 2.5.4 widened the TypeIs of np.isscalar to include numbers.Number, which xarray's DataArray.__add__ does not accept, so mypy fails on the legacy scalar branch of _add_constant. Cast to the scalar members of ConstantLike; no runtime change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: route legacy scalar add through _combined_with_constant instead of cast --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Fabian <fab.hof@gmx.de> (cherry picked from commit 86d6ad2) * fix: keep dash-named parameters in netcdf round trip (#1025) * fix: keep dash-named parameters, attributes and MultiIndex dims in read_netcdf read_netcdf assigned each data variable and attribute to its container by splitting the key at its last dash. Parameters are stored as parameters-<name>, so a parameter named my-param was assigned to parameters-my and dropped; the same happened to parameter attributes and _multiindex attributes of dimensions with a dash in their name. Keys now belong to the longest known container prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: type check with numpy 2.5.4 isscalar stubs numpy 2.5.4 widened the TypeIs of np.isscalar to include numbers.Number, which xarray's DataArray.__add__ does not accept, so mypy fails on the legacy scalar branch of _add_constant. Cast to the scalar members of ConstantLike; no runtime change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: move release note to upcoming version Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(io): compute netcdf key owners once * refactor(io): compactify netcdf key owner lookup --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Fabian <fab.hof@gmx.de> (cherry picked from commit 4117547) * fix(solvers): probe the Xpress licence, run solving tests on licensed solvers (#995) * fix(solvers): probe the Xpress licence, run solving tests on licensed solvers (#994) * test(io): to_mosek builds a task without a licence, gate it on available_solvers * test(io): name a mosek task without a licence, gate its set_names cases on available_solvers * test(io): gate the highs direct QP solve on licensed_solvers (cherry picked from commit 09d4fde) * fix: keep auxiliary coordinates of dense containers in netcdf round trip (#1024) * fix: keep auxiliary coordinates of dense containers in netcdf round trip read_netcdf dropped every non-index coordinate except MultiIndex levels to keep out the scalar coordinates of other containers that xarray attaches when selecting one container's data variables. That also dropped the auxiliary coordinates of dense variables, constraints, expressions and parameters, such as the levels on a flat dimension that v1 recommends instead of a MultiIndex. Only drop scalar coordinates owned by another container, matched on the longest prefix since names may contain dashes. Coordinates with dimensions only attach to the container whose dimensions they share. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: drop narrative comments, cover dash-named parameter with scalar coord --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Fabian <fab.hof@gmx.de> (cherry picked from commit 44ff525) * docs: release notes for v0.10.1 --------- Co-authored-by: Mayk Thewessen <mayk_12@hotmail.com> Co-authored-by: Claude Opus 5.5 <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
AI-assisted. Claude wrote the code and tests, and ran the checks listed below. I reviewed the diff.
Changes proposed in this Pull Request
read_netcdfdropped the auxiliary (non-index) coordinates of every dense variable, constraint, named expression and ofModel.parameters, also for plain naive values. With v1 recommending a flat dimension with levels as auxiliary coordinates instead of aMultiIndex, a round trip through netcdf (and sosolve(remote=...)) loses those levels. Frozen constraints already kept theirs.The drop in
get_prefixwas there because selecting one container's data variables from the merged dataset attaches the scalar coordinates of all other containers (e.g.constraints-c0-snapshotafterx.sel(snapshot=0) >= 1). Coordinates with dimensions can only attach to the container whose dimensions they share, so the read now drops only scalar coordinates owned by another container. Ownership uses the longest-prefixownerslookup from #1025, so dash-named containers resolve correctly. This also restores a container's own scalar coordinates, and makes the separateMultiIndexlevel bookkeeping inget_prefixunnecessary.Overlap with #1021: both touch
read_netcdf/get_prefixinlinopy/io.py. The code merges without conflicts; only adjacent release note bullets conflict. The tests of both pass on the merge.Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.What was checked (AI-generated)
test_model_to_netcdf_aux_coordsintest/test_io.py: a flatsnapshotdimension withtime(datetime) andperiodaux coords on a variable, a dense constraint, a named expression and a parameter; a constraintc-firstfromx.sel(snapshot=0)whose scalar coords would leak intocunder a plain prefix match; and a dash-named parametermy-paramwith scalar coords. Assertsassert_model_equal, which compares coordinates. On 0578f9c: fails with master'sio.pyand passes on the branch, under both legacy and v1 semantics.MultiIndexlevels. Probing a file shows the coords xarray attaches on selection are the scalar ones of other containers.test/test_io.pyandtest/test_csr.pyon 0578f9c: 1033 passed, 941 skipped (solver-dependent).ruff checkandruff format --checkclean.mypyreports no errors in the changed files (2 existing ones insolvers.pyandremote/oetc.py).fix/netcdf-tz-aware-coordsat 0333f66):linopy/io.pymerges cleanly,doc/release_notes.rsthas an adjacent-bullet conflict. On the merge,test/test_io.pyplustest/test_csr.py: 1051 passed.🤖 Generated with Claude Code