@@ -1179,13 +1179,23 @@ def _lcd_dtypes(a_dtype, b_dtype):
1179
1179
return np .object
1180
1180
1181
1181
1182
- def _fill_zeros (result , y , fill ):
1183
- """ if we have an integer value (or array in y)
1182
+ def _fill_zeros (result , x , y , name , fill ):
1183
+ """
1184
+ if this is a reversed op, then flip x,y
1185
+
1186
+ if we have an integer value (or array in y)
1184
1187
and we have 0's, fill them with the fill,
1185
1188
return the result
1189
+
1190
+ mask the nan's from x
1186
1191
"""
1187
1192
1188
1193
if fill is not None :
1194
+
1195
+ if name .startswith ('r' ):
1196
+ x ,y = y ,x
1197
+
1198
+
1189
1199
if not isinstance (y , np .ndarray ):
1190
1200
dtype , value = _infer_dtype_from_scalar (y )
1191
1201
y = pa .empty (result .shape , dtype = dtype )
@@ -1196,8 +1206,18 @@ def _fill_zeros(result, y, fill):
1196
1206
mask = y .ravel () == 0
1197
1207
if mask .any ():
1198
1208
shape = result .shape
1199
- result , changed = _maybe_upcast_putmask (
1200
- result .ravel (), mask , fill )
1209
+ result = result .ravel ().astype ('float64' )
1210
+
1211
+ signs = np .sign (result )
1212
+ nans = np .isnan (x .ravel ())
1213
+ np .putmask (result , mask & ~ nans , fill )
1214
+
1215
+ # if we have a fill of inf, then sign it
1216
+ # correctly
1217
+ # GH 6178
1218
+ if np .isinf (fill ):
1219
+ np .putmask (result ,signs < 0 & mask & ~ nans ,- fill )
1220
+
1201
1221
result = result .reshape (shape )
1202
1222
1203
1223
return result
0 commit comments