Skip to content

Commit beb7c48

Browse files
authored
PERF: DataFrame floordiv (#43281)
1 parent 69c673c commit beb7c48

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pandas/core/ops/missing.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def fill_zeros(result, x, y):
7474
return result
7575

7676

77-
def mask_zero_div_zero(x, y, result):
77+
def mask_zero_div_zero(x, y, result: np.ndarray) -> np.ndarray:
7878
"""
7979
Set results of 0 // 0 to np.nan, regardless of the dtypes
8080
of the numerator or the denominator.
@@ -121,10 +121,12 @@ def mask_zero_div_zero(x, y, result):
121121
zneg_mask = zmask & np.signbit(y)
122122
zpos_mask = zmask & ~zneg_mask
123123

124+
x_lt0 = x < 0
125+
x_gt0 = x > 0
124126
nan_mask = zmask & (x == 0)
125127
with np.errstate(invalid="ignore"):
126-
neginf_mask = (zpos_mask & (x < 0)) | (zneg_mask & (x > 0))
127-
posinf_mask = (zpos_mask & (x > 0)) | (zneg_mask & (x < 0))
128+
neginf_mask = (zpos_mask & x_lt0) | (zneg_mask & x_gt0)
129+
posinf_mask = (zpos_mask & x_gt0) | (zneg_mask & x_lt0)
128130

129131
if nan_mask.any() or neginf_mask.any() or posinf_mask.any():
130132
# Fill negative/0 with -inf, positive/0 with +inf, 0/0 with NaN

0 commit comments

Comments
 (0)