Skip to content

Commit ab4ad06

Browse files
committed
cleanup
1 parent b64df5b commit ab4ad06

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

xarray/core/groupby.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,11 @@ def _binary_op(self, other, f, reflexive=False):
655655
other[var].drop_vars(var).expand_dims({name: other.sizes[name]})
656656
)
657657

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
661660
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)
664663

665664
other, _ = align(other, coord, join="outer")
666665
expanded = other.isel({name: codes})
@@ -720,7 +719,7 @@ def _flox_reduce(
720719
# preserve current strategy (approximately) for dask groupby.
721720
# We want to control the default anyway to prevent surprises
722721
# if flox decides to change its default
723-
kwargs.setdefault("method", "split-reduce")
722+
kwargs.setdefault("method", "cohorts")
724723

725724
numeric_only = kwargs.pop("numeric_only", None)
726725
if numeric_only:
@@ -773,14 +772,13 @@ def _flox_reduce(
773772
# Xarray's behaviour is that empty bins have np.nan regardless of dtype
774773
# flox's default would not set np.nan for integer dtypes
775774
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
784782

785783
output_index = self._get_output_index()
786784
result = xarray_reduce(
@@ -798,10 +796,7 @@ def _flox_reduce(
798796
# in the grouped variable
799797
if set(self._codes.dims).issubset(set(parsed_dim)):
800798
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)
805800

806801
# broadcast and restore non-numeric data variables (backcompat)
807802
for name, var in non_numeric.items():

xarray/core/resample.py

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def _flox_reduce(
5252
**kwargs,
5353
) -> T_Xarray:
5454

55-
kwargs.setdefault("method", "cohorts")
5655
result = super()._flox_reduce(dim=dim, keep_attrs=keep_attrs, **kwargs)
5756
result = result.rename({RESAMPLE_DIM: self._group_dim})
5857
return result

0 commit comments

Comments
 (0)