Skip to content

Commit e7d0ab6

Browse files
committed
Fix test
1 parent 76019ed commit e7d0ab6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

xarray/core/groupby.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,14 +787,12 @@ def _maybe_restore_empty_groups(self, combined):
787787
"""Our index contained empty groups (e.g., from a resampling or binning). If we
788788
reduced on that dimension, we want to restore the full index.
789789
"""
790-
from xarray.groupers import BinGrouper, TimeResampler
791-
790+
has_missing_groups = (
791+
self.encoded.unique_coord.size != self.encoded.full_index.size
792+
)
792793
indexers = {}
793794
for grouper in self.groupers:
794-
if (
795-
isinstance(grouper.grouper, BinGrouper | TimeResampler)
796-
and grouper.name in combined.dims
797-
):
795+
if has_missing_groups and grouper.name in combined._indexes:
798796
indexers[grouper.name] = grouper.full_index
799797
if indexers:
800798
combined = combined.reindex(**indexers)

xarray/tests/test_groupby.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,9 +2802,13 @@ def test_groupby_preserve_dtype(reduction):
28022802
kwargs = {}
28032803
if "nan" in reduction:
28042804
kwargs["skipna"] = True
2805-
reduction = reduction.removeprefix("nan")
2806-
actual = getattr(ds.groupby("idx"), reduction)(**kwargs).test.dtype
2805+
# TODO: fix dtype with numbagg/bottleneck and use_flox=False
2806+
with xr.set_options(use_numbagg=False, use_bottleneck=False):
2807+
actual = getattr(ds.groupby("idx"), reduction.removeprefix("nan"))(
2808+
**kwargs
2809+
).test.dtype
28072810
expected = getattr(np, reduction)(ds.test.data, axis=0).dtype
2811+
28082812
assert actual == expected
28092813

28102814

0 commit comments

Comments
 (0)