Skip to content

Commit d88929f

Browse files
committed
Take 2
1 parent 797c790 commit d88929f

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

pandas/core/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4908,8 +4908,7 @@ def _combine_match_index(self, other, func, level=None):
49084908
return ops.dispatch_to_series(left, right, func)
49094909
else:
49104910
# fastpath --> operate directly on values
4911-
with np.errstate(all="ignore"):
4912-
new_data = func(left.values.T, right.values).T
4911+
new_data = func(left.values.T, right.values).T
49134912
return self._constructor(new_data,
49144913
index=left.index, columns=self.columns,
49154914
copy=False)

pandas/core/ops.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ def maybe_upcast_for_op(obj):
138138
return obj
139139

140140

141+
def silent_truediv(x, y):
142+
"""Like operator.truediv, but with NumPy warnings silenced."""
143+
with np.errstate(all="ignore"):
144+
return operator.truediv(x ,y)
145+
146+
147+
silent_truediv.__name__ = 'truediv'
148+
silent_truediv.__doc__ = operator.truediv.__doc__
149+
141150
# -----------------------------------------------------------------------------
142151
# Reversed Operations not available in the stdlib operator module.
143152
# Defining these instead of using lambdas allows us to reference them by name.
@@ -159,7 +168,7 @@ def rdiv(left, right):
159168

160169

161170
def rtruediv(left, right):
162-
return right / left
171+
return silent_truediv(right, left)
163172

164173

165174
def rfloordiv(left, right):
@@ -339,7 +348,7 @@ def _get_opstr(op, cls):
339348
rmul: '*',
340349
operator.sub: '-',
341350
rsub: '-',
342-
operator.truediv: '/',
351+
silent_truediv: '/',
343352
rtruediv: '/',
344353
operator.floordiv: '//',
345354
rfloordiv: '//',
@@ -1012,7 +1021,7 @@ def _create_methods(cls, arith_method, comp_method, bool_method, special):
10121021
radd=arith_method(cls, radd, special),
10131022
sub=arith_method(cls, operator.sub, special),
10141023
mul=arith_method(cls, operator.mul, special),
1015-
truediv=arith_method(cls, operator.truediv, special),
1024+
truediv=arith_method(cls, silent_truediv, special),
10161025
floordiv=arith_method(cls, operator.floordiv, special),
10171026
# Causes a floating point exception in the tests when numexpr enabled,
10181027
# so for now no speedup

pandas/tests/frame/test_operators.py

+6
Original file line numberDiff line numberDiff line change
@@ -1030,3 +1030,9 @@ def test_alignment_non_pandas(self):
10301030
align(df, val, 'index')
10311031
with pytest.raises(ValueError):
10321032
align(df, val, 'columns')
1033+
1034+
def test_no_warning(self, all_arithmetic_operators):
1035+
df = pd.DataFrame({"A": [0.,0.], "B": [0., None]})
1036+
b = df['B']
1037+
with tm.assert_produces_warning(None):
1038+
getattr(df, all_arithmetic_operators)(b, 0)

0 commit comments

Comments
 (0)