Skip to content

Commit e059cc7

Browse files
authored
Fix generator exhaustion in combine_by_coords (#11265)
* 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
1 parent d0ee979 commit e059cc7

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Bug Fixes
116116
- Fix :py:meth:`Dataset.interp` silently dropping datetime64 and timedelta64
117117
variables, through enabling their interpolation (:issue:`10900`, :pull:`11081`).
118118
By `Emmanuel Ferdman <https://github.com/emmanuel-ferdman>`_.
119+
- :func:`combine_by_coords` no longer returns an empty dataset when a generator is passed as ``data_objects`` (:issue:`10114`, :pull:`11265`).
120+
By `Amartya Anand <https://github.com/SurfyPenguin>`_.
119121

120122
Documentation
121123
~~~~~~~~~~~~~

xarray/structure/combine.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,8 @@ def combine_by_coords(
10741074
Finally, if you attempt to combine a mix of unnamed DataArrays with either named
10751075
DataArrays or Datasets, a ValueError will be raised (as this is an ambiguous operation).
10761076
"""
1077+
data_objects = list(data_objects)
1078+
10771079
if any(isinstance(data_object, DataTree) for data_object in data_objects):
10781080
raise NotImplementedError(
10791081
"combine_by_coords() does not yet support DataTree objects."

0 commit comments

Comments
 (0)