Skip to content

Commit 01b1afe

Browse files
Fix reductions on boolean reductions. (#104)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1803f77 commit 01b1afe

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

flox/core.py

+2
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,8 @@ def groupby_reduce(
14651465

14661466
if not is_duck_array(array):
14671467
array = np.asarray(array)
1468+
array = array.astype(int) if np.issubdtype(array.dtype, bool) else array
1469+
14681470
if isinstance(isbin, bool):
14691471
isbin = (isbin,) * len(by)
14701472
if expected_groups is None:

tests/test_core.py

+11
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,17 @@ def test_datetime_binning():
830830
assert_equal(group_idx, expected)
831831

832832

833+
@pytest.mark.parametrize("func", ALL_FUNCS)
834+
def test_bool_reductions(func, engine):
835+
if "arg" in func and engine == "flox":
836+
pytest.skip()
837+
groups = np.array([1, 1, 1])
838+
data = np.array([True, True, False])
839+
expected = np.expand_dims(getattr(np, func)(data), -1)
840+
actual, _ = groupby_reduce(data, groups, func=func, engine=engine)
841+
assert_equal(expected, actual)
842+
843+
833844
@requires_dask
834845
def test_map_reduce_blockwise_mixed():
835846
t = pd.date_range("2000-01-01", "2000-12-31", freq="D").to_series()

0 commit comments

Comments
 (0)