Skip to content

Commit d5f7723

Browse files
PERF: only apply nanops rowwise optimization for narrow arrows (#44566)
1 parent 8bd9f64 commit d5f7723

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pandas/core/nanops.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ def _na_for_min_count(values: np.ndarray, axis: int | None) -> Scalar | np.ndarr
455455
def maybe_operate_rowwise(func: F) -> F:
456456
"""
457457
NumPy operations on C-contiguous ndarrays with axis=1 can be
458-
very slow. Operate row-by-row and concatenate the results.
458+
very slow if axis 1 >> axis 0.
459+
Operate row-by-row and concatenate the results.
459460
"""
460461

461462
@functools.wraps(func)
@@ -464,6 +465,9 @@ def newfunc(values: np.ndarray, *, axis: int | None = None, **kwargs):
464465
axis == 1
465466
and values.ndim == 2
466467
and values.flags["C_CONTIGUOUS"]
468+
# only takes this path for wide arrays (long dataframes), for threshold see
469+
# https://github.com/pandas-dev/pandas/pull/43311#issuecomment-974891737
470+
and (values.shape[1] / 1000) > values.shape[0]
467471
and values.dtype != object
468472
and values.dtype != bool
469473
):

0 commit comments

Comments
 (0)