30
30
from .roperator import rdivmod , rfloordiv , rmod
31
31
32
32
33
- def fill_zeros (result , x , y , name , fill ):
33
+ def fill_zeros (result , x , y ):
34
34
"""
35
35
If this is a reversed op, then flip x,y
36
36
37
37
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 ,
39
39
return the result.
40
40
41
41
Mask the nan's from x.
42
42
"""
43
- if fill is None or is_float_dtype (result .dtype ):
43
+ if is_float_dtype (result .dtype ):
44
44
return result
45
45
46
- if name .startswith (("r" , "__r" )):
47
- x , y = y , x
48
-
49
46
is_variable_type = hasattr (y , "dtype" ) or hasattr (y , "type" )
50
47
is_scalar_type = is_scalar (y )
51
48
@@ -66,19 +63,7 @@ def fill_zeros(result, x, y, name, fill):
66
63
shape = result .shape
67
64
result = result .astype ("float64" , copy = False ).ravel ()
68
65
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 )
82
67
83
68
result = result .reshape (shape )
84
69
@@ -172,12 +157,12 @@ def dispatch_fill_zeros(op, left, right, result):
172
157
if op is divmod :
173
158
result = (
174
159
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 ),
176
161
)
177
162
elif op is rdivmod :
178
163
result = (
179
164
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 ),
181
166
)
182
167
elif op is operator .floordiv :
183
168
# 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):
188
173
# we want.
189
174
result = mask_zero_div_zero (right , left , result )
190
175
elif op is operator .mod :
191
- result = fill_zeros (result , left , right , "__mod__" , np . nan )
176
+ result = fill_zeros (result , left , right )
192
177
elif op is rmod :
193
- result = fill_zeros (result , left , right , "__rmod__" , np . nan )
178
+ result = fill_zeros (result , right , left )
194
179
return result
0 commit comments