Skip to content

Commit b4dcf3b

Browse files
PERF: fix regression in reductions for boolean/integer data (#41924)
Co-authored-by: Brock <[email protected]>
1 parent d265e21 commit b4dcf3b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pandas/core/nanops.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ def _maybe_get_mask(
245245
"""
246246
if mask is None:
247247
if is_bool_dtype(values.dtype) or is_integer_dtype(values.dtype):
248-
return np.broadcast_to(False, values.shape)
248+
# Boolean data cannot contain nulls, so signal via mask being None
249+
return None
249250

250251
if skipna or needs_i8_conversion(values.dtype):
251252
mask = isna(values)
@@ -1435,8 +1436,15 @@ def _maybe_null_out(
14351436
Dtype
14361437
The product of all elements on a given axis. ( NaNs are treated as 1)
14371438
"""
1438-
if mask is not None and axis is not None and isinstance(result, np.ndarray):
1439-
null_mask = (mask.shape[axis] - mask.sum(axis) - min_count) < 0
1439+
if axis is not None and isinstance(result, np.ndarray):
1440+
if mask is not None:
1441+
null_mask = (mask.shape[axis] - mask.sum(axis) - min_count) < 0
1442+
else:
1443+
# we have no nulls, kept mask=None in _maybe_get_mask
1444+
below_count = shape[axis] - min_count < 0
1445+
new_shape = shape[:axis] + shape[axis + 1 :]
1446+
null_mask = np.broadcast_to(below_count, new_shape)
1447+
14401448
if np.any(null_mask):
14411449
if is_numeric_dtype(result):
14421450
if np.iscomplexobj(result):

0 commit comments

Comments
 (0)