File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -787,14 +787,12 @@ def _maybe_restore_empty_groups(self, combined):
787
787
"""Our index contained empty groups (e.g., from a resampling or binning). If we
788
788
reduced on that dimension, we want to restore the full index.
789
789
"""
790
- from xarray .groupers import BinGrouper , TimeResampler
791
-
790
+ has_missing_groups = (
791
+ self .encoded .unique_coord .size != self .encoded .full_index .size
792
+ )
792
793
indexers = {}
793
794
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 :
798
796
indexers [grouper .name ] = grouper .full_index
799
797
if indexers :
800
798
combined = combined .reindex (** indexers )
Original file line number Diff line number Diff line change @@ -2802,9 +2802,13 @@ def test_groupby_preserve_dtype(reduction):
2802
2802
kwargs = {}
2803
2803
if "nan" in reduction :
2804
2804
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
2807
2810
expected = getattr (np , reduction )(ds .test .data , axis = 0 ).dtype
2811
+
2808
2812
assert actual == expected
2809
2813
2810
2814
You can’t perform that action at this time.
0 commit comments