fix: xarray 2026.4 Dataset-into-Dataset TypeError#657
Closed
Conversation
xarray 2026.4.0 raises TypeError when Dataset() is called with an existing
Dataset as data_vars ("Use ds.copy() instead"). Three call sites in
expressions.py wrapped an already-constructed Dataset returned by
.transpose() / .assign_coords() — drop the redundant wrap. Model.parameters
setter may also receive a Dataset; switch to .copy() in that case.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Duplicate of #647 which is already merged. My local checkout was stale — sorry for the noise. |
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.
Summary
xarray 2026.4.0 now raises
TypeError: Passing a Dataset as 'data_vars' to the Dataset constructor is not supportedwhen an existingDatasetis passed toDataset(). This brokelinopy.Model()construction and the RTD docs build (see #656).Three call sites in
expressions.pywrapped an already-Dataset return from.transpose()/.assign_coords()in a redundantDataset(...). TheModel.parameterssetter also wrapped a potentialDatasetinput — switched to.copy()in that branch.Changes
linopy/expressions.py:287— dropxr.Dataset(...)wrap aroundds.assign_coords(new_coords)linopy/expressions.py:395— dropDataset(...)wrap arounddata.transpose(..., TERM_DIM)linopy/expressions.py:2101— dropxr.Dataset(...)wrap arounddata.transpose(..., FACTOR_DIM, TERM_DIM)linopy/model.py:362—Model.parameterssetter now uses.copy()for Dataset inputsTest plan
Model()constructs under xarray 2026.4.0🤖 Generated with Claude Code