@@ -138,6 +138,15 @@ def maybe_upcast_for_op(obj):
138
138
return obj
139
139
140
140
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
+
141
150
# -----------------------------------------------------------------------------
142
151
# Reversed Operations not available in the stdlib operator module.
143
152
# Defining these instead of using lambdas allows us to reference them by name.
@@ -159,7 +168,7 @@ def rdiv(left, right):
159
168
160
169
161
170
def rtruediv (left , right ):
162
- return right / left
171
+ return silent_truediv ( right , left )
163
172
164
173
165
174
def rfloordiv (left , right ):
@@ -339,7 +348,7 @@ def _get_opstr(op, cls):
339
348
rmul : '*' ,
340
349
operator .sub : '-' ,
341
350
rsub : '-' ,
342
- operator . truediv : '/' ,
351
+ silent_truediv : '/' ,
343
352
rtruediv : '/' ,
344
353
operator .floordiv : '//' ,
345
354
rfloordiv : '//' ,
@@ -1012,7 +1021,7 @@ def _create_methods(cls, arith_method, comp_method, bool_method, special):
1012
1021
radd = arith_method (cls , radd , special ),
1013
1022
sub = arith_method (cls , operator .sub , special ),
1014
1023
mul = arith_method (cls , operator .mul , special ),
1015
- truediv = arith_method (cls , operator . truediv , special ),
1024
+ truediv = arith_method (cls , silent_truediv , special ),
1016
1025
floordiv = arith_method (cls , operator .floordiv , special ),
1017
1026
# Causes a floating point exception in the tests when numexpr enabled,
1018
1027
# so for now no speedup
0 commit comments