@@ -838,45 +838,20 @@ def t(expect, func, n, m):
838838
839839 def test_safe_casting (self ):
840840 # In old versions of numpy, in-place operations used the 'unsafe'
841- # casting rules. In some future version, 'same_kind' will become the
842- # default.
841+ # casting rules. In versions >= 1.10, 'same_kind' is the
842+ # default and an exception is raised instead of a warning.
843+ # when 'same_kind' is not satisfied.
843844 a = np .array ([1 , 2 , 3 ], dtype = int )
844845 # Non-in-place addition is fine
845846 assert_array_equal (assert_no_warnings (np .add , a , 1.1 ),
846847 [2.1 , 3.1 , 4.1 ])
847- assert_warns (DeprecationWarning , np .add , a , 1.1 , out = a )
848- assert_array_equal (a , [2 , 3 , 4 ])
848+ assert_raises (TypeError , np .add , a , 1.1 , out = a )
849849 def add_inplace (a , b ):
850850 a += b
851- assert_warns (DeprecationWarning , add_inplace , a , 1.1 )
852- assert_array_equal (a , [3 , 4 , 5 ])
853- # Make sure that explicitly overriding the warning is allowed:
851+ assert_raises (TypeError , add_inplace , a , 1.1 )
852+ # Make sure that explicitly overriding the exception is allowed:
854853 assert_no_warnings (np .add , a , 1.1 , out = a , casting = "unsafe" )
855- assert_array_equal (a , [4 , 5 , 6 ])
856-
857- # There's no way to propagate exceptions from the place where we issue
858- # this deprecation warning, so we must throw the exception away
859- # entirely rather than cause it to be raised at some other point, or
860- # trigger some other unsuspecting if (PyErr_Occurred()) { ...} at some
861- # other location entirely.
862- import warnings
863- import sys
864- if sys .version_info [0 ] >= 3 :
865- from io import StringIO
866- else :
867- from StringIO import StringIO
868- with warnings .catch_warnings ():
869- warnings .simplefilter ("error" )
870- old_stderr = sys .stderr
871- try :
872- sys .stderr = StringIO ()
873- # No error, but dumps to stderr
874- a += 1.1
875- # No error on the next bit of code executed either
876- 1 + 1
877- assert_ ("Implicitly casting" in sys .stderr .getvalue ())
878- finally :
879- sys .stderr = old_stderr
854+ assert_array_equal (a , [2 , 3 , 4 ])
880855
881856 def test_ufunc_custom_out (self ):
882857 # Test ufunc with built in input types and custom output type
0 commit comments