From 5212a5bcef5d078a08bd71906df58fded92a365a Mon Sep 17 00:00:00 2001 From: dcherian Date: Tue, 25 Apr 2023 22:10:30 -0600 Subject: [PATCH] Better? --- flox/core.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/flox/core.py b/flox/core.py index e7ab0967..d84639bc 100644 --- a/flox/core.py +++ b/flox/core.py @@ -2324,6 +2324,7 @@ def groupby_reduce( nby = len(bys) by_is_dask = tuple(is_duck_dask_array(b) for b in bys) any_by_dask = any(by_is_dask) + provided_expected = expected_groups is not None if ( engine == "numbagg" @@ -2440,7 +2441,7 @@ def groupby_reduce( # The only way to do this consistently is mask out using min_count # Consider np.sum([np.nan]) = np.nan, np.nansum([np.nan]) = 0 if min_count is None: - if nax < by_.ndim or fill_value is not None: + if nax < by_.ndim or (fill_value is not None and provided_expected): min_count_: int = 1 else: min_count_ = 0 @@ -2486,12 +2487,6 @@ def groupby_reduce( return (result, groups) elif not has_dask: - if min_count_ == 1: - # optimize for pure numpy groupby - # We set the fill_value appropriately anyway - agg.min_count = None - agg.numpy = agg.numpy[:-1] - results = _reduce_blockwise( array, by_, agg, expected_groups=expected_, reindex=reindex, sort=sort, **kwargs )