Skip to content

Commit 6d6d4c9

Browse files
Backport PR #41924: PERF: fix regression in reductions for boolean/integer data (#41963)
Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 322d54a commit 6d6d4c9

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
@@ -231,7 +231,8 @@ def _maybe_get_mask(
231231
"""
232232
if mask is None:
233233
if is_bool_dtype(values.dtype) or is_integer_dtype(values.dtype):
234-
return np.broadcast_to(False, values.shape)
234+
# Boolean data cannot contain nulls, so signal via mask being None
235+
return None
235236

236237
if skipna or needs_i8_conversion(values.dtype):
237238
mask = isna(values)
@@ -1376,8 +1377,15 @@ def _maybe_null_out(
13761377
Dtype
13771378
The product of all elements on a given axis. ( NaNs are treated as 1)
13781379
"""
1379-
if mask is not None and axis is not None and getattr(result, "ndim", False):
1380-
null_mask = (mask.shape[axis] - mask.sum(axis) - min_count) < 0
1380+
if axis is not None and isinstance(result, np.ndarray):
1381+
if mask is not None:
1382+
null_mask = (mask.shape[axis] - mask.sum(axis) - min_count) < 0
1383+
else:
1384+
# we have no nulls, kept mask=None in _maybe_get_mask
1385+
below_count = shape[axis] - min_count < 0
1386+
new_shape = shape[:axis] + shape[axis + 1 :]
1387+
null_mask = np.broadcast_to(below_count, new_shape)
1388+
13811389
if np.any(null_mask):
13821390
if is_numeric_dtype(result):
13831391
if np.iscomplexobj(result):

0 commit comments

Comments
 (0)