Skip to content

Commit 1f5fd9c

Browse files
jbrockmendelproost
authored andcommitted
CLN: small ops cleanup (pandas-dev#28379)
1 parent e2eff13 commit 1f5fd9c

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

pandas/core/ops/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
ensure_object,
1919
is_bool_dtype,
2020
is_datetime64_dtype,
21-
is_datetimelike_v_numeric,
2221
is_extension_array_dtype,
2322
is_integer_dtype,
2423
is_list_like,
@@ -672,9 +671,6 @@ def na_op(x, y):
672671
if is_object_dtype(x.dtype):
673672
result = comp_method_OBJECT_ARRAY(op, x, y)
674673

675-
elif is_datetimelike_v_numeric(x, y):
676-
return invalid_comparison(x, y, op)
677-
678674
else:
679675
method = getattr(x, op_name)
680676
with np.errstate(all="ignore"):

pandas/core/ops/missing.py

+8-23
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,19 @@
3030
from .roperator import rdivmod, rfloordiv, rmod
3131

3232

33-
def fill_zeros(result, x, y, name, fill):
33+
def fill_zeros(result, x, y):
3434
"""
3535
If this is a reversed op, then flip x,y
3636
3737
If we have an integer value (or array in y)
38-
and we have 0's, fill them with the fill,
38+
and we have 0's, fill them with np.nan,
3939
return the result.
4040
4141
Mask the nan's from x.
4242
"""
43-
if fill is None or is_float_dtype(result.dtype):
43+
if is_float_dtype(result.dtype):
4444
return result
4545

46-
if name.startswith(("r", "__r")):
47-
x, y = y, x
48-
4946
is_variable_type = hasattr(y, "dtype") or hasattr(y, "type")
5047
is_scalar_type = is_scalar(y)
5148

@@ -66,19 +63,7 @@ def fill_zeros(result, x, y, name, fill):
6663
shape = result.shape
6764
result = result.astype("float64", copy=False).ravel()
6865

69-
np.putmask(result, mask, fill)
70-
71-
# if we have a fill of inf, then sign it correctly
72-
# (GH#6178 and GH#9308)
73-
if np.isinf(fill):
74-
signs = y if name.startswith(("r", "__r")) else x
75-
signs = np.sign(signs.astype("float", copy=False))
76-
negative_inf_mask = (signs.ravel() < 0) & mask
77-
np.putmask(result, negative_inf_mask, -fill)
78-
79-
if "floordiv" in name: # (GH#9308)
80-
nan_mask = ((y == 0) & (x == 0)).ravel()
81-
np.putmask(result, nan_mask, np.nan)
66+
np.putmask(result, mask, np.nan)
8267

8368
result = result.reshape(shape)
8469

@@ -172,12 +157,12 @@ def dispatch_fill_zeros(op, left, right, result):
172157
if op is divmod:
173158
result = (
174159
mask_zero_div_zero(left, right, result[0]),
175-
fill_zeros(result[1], left, right, "__mod__", np.nan),
160+
fill_zeros(result[1], left, right),
176161
)
177162
elif op is rdivmod:
178163
result = (
179164
mask_zero_div_zero(right, left, result[0]),
180-
fill_zeros(result[1], left, right, "__rmod__", np.nan),
165+
fill_zeros(result[1], right, left),
181166
)
182167
elif op is operator.floordiv:
183168
# Note: no need to do this for truediv; in py3 numpy behaves the way
@@ -188,7 +173,7 @@ def dispatch_fill_zeros(op, left, right, result):
188173
# we want.
189174
result = mask_zero_div_zero(right, left, result)
190175
elif op is operator.mod:
191-
result = fill_zeros(result, left, right, "__mod__", np.nan)
176+
result = fill_zeros(result, left, right)
192177
elif op is rmod:
193-
result = fill_zeros(result, left, right, "__rmod__", np.nan)
178+
result = fill_zeros(result, right, left)
194179
return result

0 commit comments

Comments
 (0)