Skip to content

Commit

Permalink
Better?
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed May 2, 2024
1 parent 2f4f6ec commit 5212a5b
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions flox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 5212a5b

Please sign in to comment.