From e059cc7a522b2693b8b921048fdf499912b88f2c Mon Sep 17 00:00:00 2001 From: frostByte <186186766+SurfyPenguin@users.noreply.github.com> Date: Thu, 2 Apr 2026 18:52:39 +0530 Subject: [PATCH] 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 --- doc/whats-new.rst | 2 ++ xarray/structure/combine.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index ca172a3a85a..2b1e1c354eb 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -116,6 +116,8 @@ Bug Fixes - Fix :py:meth:`Dataset.interp` silently dropping datetime64 and timedelta64 variables, through enabling their interpolation (:issue:`10900`, :pull:`11081`). By `Emmanuel Ferdman `_. +- :func:`combine_by_coords` no longer returns an empty dataset when a generator is passed as ``data_objects`` (:issue:`10114`, :pull:`11265`). + By `Amartya Anand `_. Documentation ~~~~~~~~~~~~~ diff --git a/xarray/structure/combine.py b/xarray/structure/combine.py index e8e973683d0..6699b32d8fa 100644 --- a/xarray/structure/combine.py +++ b/xarray/structure/combine.py @@ -1074,6 +1074,8 @@ def combine_by_coords( Finally, if you attempt to combine a mix of unnamed DataArrays with either named DataArrays or Datasets, a ValueError will be raised (as this is an ambiguous operation). """ + data_objects = list(data_objects) + if any(isinstance(data_object, DataTree) for data_object in data_objects): raise NotImplementedError( "combine_by_coords() does not yet support DataTree objects."