Skip to content

fix: use xarray.Dataset copy instead of constructor#647

Merged
coroa merged 3 commits intoPyPSA:masterfrom
maurerle:xarray_update
Apr 17, 2026
Merged

fix: use xarray.Dataset copy instead of constructor#647
coroa merged 3 commits intoPyPSA:masterfrom
maurerle:xarray_update

Conversation

@maurerle
Copy link
Copy Markdown
Contributor

minimal non-working example:

import pypsa
network = pypsa.examples.ac_dc_meshed()
network.optimize()

Changes proposed in this Pull Request

since the latest xarray version, passing a Dataset as data_vars to the Dataset constructor is not supported. Use ds.copy() to create a copy of a Dataset.

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • 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.

FBumann

This comment was marked as spam.

Copy link
Copy Markdown
Collaborator

@FBumann FBumann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure if we should exclude highspy==1.14.0 from linopy deps. This PR gets the CI working, but users will get wring results with highs. Not fully our responsibility, but worth considering

Comment thread linopy/expressions.py Outdated
Comment thread linopy/expressions.py Outdated
Comment thread linopy/expressions.py Outdated
@coroa
Copy link
Copy Markdown
Member

coroa commented Apr 17, 2026

Im not sure if we should exclude highspy==1.14.0 from linopy deps. This PR gets the CI working, but users will get wring results with highs. Not fully our responsibility, but worth considering

Yes, we should, but not in this PR.

Comment thread linopy/expressions.py Outdated
Comment thread test/test_optimization.py Outdated
Comment thread linopy/model.py
@maurerle
Copy link
Copy Markdown
Contributor Author

The CI does not run through because of missing #654

@maurerle maurerle mentioned this pull request Apr 17, 2026
4 tasks
Comment thread linopy/expressions.py Outdated
# transpose with new Dataset to really ensure correct order
data = Dataset(data.transpose(..., TERM_DIM))
# Ensure correct dimension order and materialize a new Dataset.
# Wrapping an existing Dataset in Dataset(...) is no longer supported
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Wrapping an existing Dataset in Dataset(...) is no longer supported

Remove this explanation. After we merge this it adds nothing. Its more like a commit message

Comment thread linopy/expressions.py Outdated
data = Dataset(data.transpose(..., TERM_DIM))
# Ensure correct dimension order and materialize a new Dataset.
# Wrapping an existing Dataset in Dataset(...) is no longer supported
# by newer xarray versions.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# by newer xarray versions.

Remove this explanation. After we merge this it adds nothing. Its more like a commit message

since the latest xarray version, passing a Dataset as `data_vars` to the Dataset constructor is not supported.
transpose and assign_coords already returns a new dataset.
@coroa coroa merged commit 339e142 into PyPSA:master Apr 17, 2026
21 checks passed
@coroa
Copy link
Copy Markdown
Member

coroa commented Apr 17, 2026

Ok, thanks. I'll see if i can get a release out today or latest on Monday.

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.

3 participants