Skip to content

Fix generator exhaustion in combine_by_coords#11265

Merged
headtr1ck merged 3 commits into
pydata:mainfrom
SurfyPenguin:fix/combine-by-coords-returns-empty-dataset
Apr 2, 2026
Merged

Fix generator exhaustion in combine_by_coords#11265
headtr1ck merged 3 commits into
pydata:mainfrom
SurfyPenguin:fix/combine-by-coords-returns-empty-dataset

Conversation

@SurfyPenguin

Copy link
Copy Markdown
Contributor

This pull request applies the suggested fix tracked in #10114 and fixes combine_by_coords returning an empty Dataset when a generator is passed as data_objects.

`combine_by_coords` accepts `Iterable[Dataset | DataArray]`.

When a generator is passed, it is exhausted by the `DataTree` isinstance
check before `objs_are_unnamed_dataarrays` is assigned, causing subsequent
iterations to yield nothing and returning an empty Dataset.

Fix by materializing `data_objects` into a list.
@welcome

welcome Bot commented Mar 26, 2026

Copy link
Copy Markdown

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

@headtr1ck headtr1ck added bug plan to merge Final call for comments labels Mar 26, 2026
@headtr1ck headtr1ck enabled auto-merge (squash) April 2, 2026 12:56
@headtr1ck headtr1ck merged commit e059cc7 into pydata:main Apr 2, 2026
39 of 40 checks passed
spencerkclark pushed a commit to spencerkclark/xarray that referenced this pull request Apr 4, 2026
* Fix generator exhaustion in combine_by_coords

`combine_by_coords` accepts `Iterable[Dataset | DataArray]`.

When a generator is passed, it is exhausted by the `DataTree` isinstance
check before `objs_are_unnamed_dataarrays` is assigned, causing subsequent
iterations to yield nothing and returning an empty Dataset.

Fix by materializing `data_objects` into a list.

* Add entry in whats-new.rst
jsignell pushed a commit to jsignell/xarray that referenced this pull request Apr 15, 2026
* Fix generator exhaustion in combine_by_coords

`combine_by_coords` accepts `Iterable[Dataset | DataArray]`.

When a generator is passed, it is exhausted by the `DataTree` isinstance
check before `objs_are_unnamed_dataarrays` is assigned, causing subsequent
iterations to yield nothing and returning an empty Dataset.

Fix by materializing `data_objects` into a list.

* Add entry in whats-new.rst
@SurfyPenguin SurfyPenguin deleted the fix/combine-by-coords-returns-empty-dataset branch April 22, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug plan to merge Final call for comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iterable[Dataset | DataArray] issue with xarray.core.combine.combine_by_coords

2 participants