Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERF: use arr.size instead of np.prod(arr.shape) in _can_use_numexpr #39825

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/array_algos/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def shift(values: np.ndarray, periods: int, axis: int, fill_value) -> np.ndarray
new_values = new_values.T
axis = new_values.ndim - axis - 1

if np.prod(new_values.shape):
if new_values.size:
new_values = np.roll(new_values, ensure_platform_int(periods), axis=axis)

axis_indexer = [slice(None)] * values.ndim
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _can_use_numexpr(op, op_str, a, b, dtype_check):
if op_str is not None:

# required min elements (otherwise we are adding overhead)
if np.prod(a.shape) > _MIN_ELEMENTS:
if a.size > _MIN_ELEMENTS:
# check for dtype compatibility
dtypes: Set[str] = set()
for o in [a, b]:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ def maybe_cast_to_datetime(value, dtype: Optional[DtypeObj]):
value = iNaT

# we have an array of datetime or timedeltas & nulls
elif np.prod(value.shape) or not is_dtype_equal(value.dtype, dtype):
elif value.size or not is_dtype_equal(value.dtype, dtype):
_disallow_mismatched_datetimelike(value, dtype)

try:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def array_equivalent(

# NaNs can occur in float and complex arrays.
if is_float_dtype(left.dtype) or is_complex_dtype(left.dtype):
if not (np.prod(left.shape) and np.prod(right.shape)):
if not (left.size and right.size):
return True
return ((left == right) | (isna(left) & isna(right))).all()

Expand Down