diff --git a/flox/core.py b/flox/core.py index 189c3e080..008d3f483 100644 --- a/flox/core.py +++ b/flox/core.py @@ -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: diff --git a/tests/test_core.py b/tests/test_core.py index c55ee8d91..71e3b9bed 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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()