Skip to content

Commit 9d496eb

Browse files
also add for boolean
1 parent 899913d commit 9d496eb

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

pandas/core/arrays/boolean.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,9 @@ def _reduce(self, name: str, skipna: bool = True, **kwargs):
696696
data = self._data
697697
mask = self._mask
698698

699-
if name == "sum":
700-
return masked_reductions.sum(data, mask, skipna=skipna, **kwargs)
699+
if name in {"sum", "min", "max"}:
700+
op = getattr(masked_reductions, name)
701+
return op(data, mask, skipna=skipna, **kwargs)
701702

702703
# coerce to a nan-aware float if needed
703704
if self._hasna:
@@ -715,9 +716,6 @@ def _reduce(self, name: str, skipna: bool = True, **kwargs):
715716
if int_result == result:
716717
result = int_result
717718

718-
elif name in ["min", "max"] and notna(result):
719-
result = np.bool_(result)
720-
721719
return result
722720

723721
def _maybe_mask_result(self, result, mask, other, op_name: str):

pandas/tests/reductions/test_reductions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,16 @@ def test_ops(self, opname, obj):
7070
[
7171
("object", 2.0),
7272
("float64", 2.0),
73-
("Int64", 2),
7473
("datetime64[ns]", datetime(2011, 11, 1)),
74+
("Int64", 2),
75+
("boolean", True),
7576
],
7677
)
7778
def test_nanminmax(self, opname, dtype, val, index_or_series):
7879
# GH#7261
7980
klass = index_or_series
8081

81-
if dtype == "Int64" and klass == pd.Index:
82+
if dtype in ["Int64", "boolean"] and klass == pd.Index:
8283
pytest.skip("EAs can't yet be stored in an index")
8384

8485
def check_missing(res):

0 commit comments

Comments
 (0)