Skip to content

fix: xarray 2026.4 Dataset-into-Dataset TypeError#657

Closed
FBumann wants to merge 1 commit intomasterfrom
fix/xarray-2026-dataset-compat
Closed

fix: xarray 2026.4 Dataset-into-Dataset TypeError#657
FBumann wants to merge 1 commit intomasterfrom
fix/xarray-2026-dataset-compat

Conversation

@FBumann
Copy link
Copy Markdown
Collaborator

@FBumann FBumann commented Apr 20, 2026

Summary

xarray 2026.4.0 now raises TypeError: Passing a Dataset as 'data_vars' to the Dataset constructor is not supported when an existing Dataset is passed to Dataset(). This broke linopy.Model() construction and the RTD docs build (see #656).

Three call sites in expressions.py wrapped an already-Dataset return from .transpose() / .assign_coords() in a redundant Dataset(...). The Model.parameters setter also wrapped a potential Dataset input — switched to .copy() in that branch.

Changes

  • linopy/expressions.py:287 — drop xr.Dataset(...) wrap around ds.assign_coords(new_coords)
  • linopy/expressions.py:395 — drop Dataset(...) wrap around data.transpose(..., TERM_DIM)
  • linopy/expressions.py:2101 — drop xr.Dataset(...) wrap around data.transpose(..., FACTOR_DIM, TERM_DIM)
  • linopy/model.py:362Model.parameters setter now uses .copy() for Dataset inputs

Test plan

  • Model() constructs under xarray 2026.4.0
  • Full non-solver test suite passes (1252 passed, 7 skipped) — exercises the previously-broken groupby-with-dataframe path
  • RTD docs build succeeds on the PR preview

🤖 Generated with Claude Code

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>
@FBumann
Copy link
Copy Markdown
Collaborator Author

FBumann commented Apr 20, 2026

Duplicate of #647 which is already merged. My local checkout was stale — sorry for the noise.

@FBumann FBumann closed this Apr 20, 2026
@FBumann FBumann deleted the fix/xarray-2026-dataset-compat branch April 20, 2026 07:38
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