Skip to content

Commit

Permalink
Fix reductions on boolean reductions. (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
dcherian and pre-commit-ci[bot] authored May 17, 2022
1 parent 1803f77 commit 01b1afe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions flox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,8 @@ def groupby_reduce(

if not is_duck_array(array):
array = np.asarray(array)
array = array.astype(int) if np.issubdtype(array.dtype, bool) else array

if isinstance(isbin, bool):
isbin = (isbin,) * len(by)
if expected_groups is None:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,17 @@ def test_datetime_binning():
assert_equal(group_idx, expected)


@pytest.mark.parametrize("func", ALL_FUNCS)
def test_bool_reductions(func, engine):
if "arg" in func and engine == "flox":
pytest.skip()
groups = np.array([1, 1, 1])
data = np.array([True, True, False])
expected = np.expand_dims(getattr(np, func)(data), -1)
actual, _ = groupby_reduce(data, groups, func=func, engine=engine)
assert_equal(expected, actual)


@requires_dask
def test_map_reduce_blockwise_mixed():
t = pd.date_range("2000-01-01", "2000-12-31", freq="D").to_series()
Expand Down

0 comments on commit 01b1afe

Please sign in to comment.