@@ -655,12 +655,11 @@ def _binary_op(self, other, f, reflexive=False):
655
655
other [var ].drop_vars (var ).expand_dims ({name : other .sizes [name ]})
656
656
)
657
657
658
- # need to handle NaNs in group or
659
- # elements that don't belong to any bins
660
- mask = self ._codes == - 1
658
+ # need to handle NaNs in group or elements that don't belong to any bins
659
+ mask = codes == - 1
661
660
if mask .any ():
662
- obj = self . _original_obj .where (~ mask , drop = True )
663
- codes = self . _codes .where (~ mask , drop = True ).astype (int )
661
+ obj = obj .where (~ mask , drop = True )
662
+ codes = codes .where (~ mask , drop = True ).astype (int )
664
663
665
664
other , _ = align (other , coord , join = "outer" )
666
665
expanded = other .isel ({name : codes })
@@ -720,7 +719,7 @@ def _flox_reduce(
720
719
# preserve current strategy (approximately) for dask groupby.
721
720
# We want to control the default anyway to prevent surprises
722
721
# if flox decides to change its default
723
- kwargs .setdefault ("method" , "split-reduce " )
722
+ kwargs .setdefault ("method" , "cohorts " )
724
723
725
724
numeric_only = kwargs .pop ("numeric_only" , None )
726
725
if numeric_only :
@@ -773,14 +772,13 @@ def _flox_reduce(
773
772
# Xarray's behaviour is that empty bins have np.nan regardless of dtype
774
773
# flox's default would not set np.nan for integer dtypes
775
774
kwargs .setdefault ("fill_value" , np .nan )
776
- if self ._bins is not None :
777
- if kwargs ["func" ] == "count" :
778
- # This is an annoying hack. Xarray returns np.nan
779
- # when there are no observations in a bin, instead of 0.
780
- # We can fake that here by forcing min_count=1.
781
- # note min_count makes no sense in the xarray world
782
- # as a kwarg for count, so this should be OK
783
- kwargs ["min_count" ] = 1
775
+ if self ._bins is not None and kwargs ["func" ] == "count" :
776
+ # This is an annoying hack. Xarray returns np.nan
777
+ # when there are no observations in a bin, instead of 0.
778
+ # We can fake that here by forcing min_count=1.
779
+ # note min_count makes no sense in the xarray world
780
+ # as a kwarg for count, so this should be OK
781
+ kwargs ["min_count" ] = 1
784
782
785
783
output_index = self ._get_output_index ()
786
784
result = xarray_reduce (
@@ -798,10 +796,7 @@ def _flox_reduce(
798
796
# in the grouped variable
799
797
if set (self ._codes .dims ).issubset (set (parsed_dim )):
800
798
result [self ._unique_coord .name ] = output_index
801
-
802
- # Ignore error when the groupby reduction is effectively
803
- # a reduction of the underlying dataset
804
- result = result .drop_vars (unindexed_dims , errors = "ignore" )
799
+ result = result .drop_vars (unindexed_dims )
805
800
806
801
# broadcast and restore non-numeric data variables (backcompat)
807
802
for name , var in non_numeric .items ():
0 commit comments