Repository: scipy/scipy

Issue:
filter out convergence warnings in optimization tests
The `optimize` tests now give `RuntimeWarning`s promoted to Exceptions with development versions of numpy.  If someone wants to go through the tests and add converge annotations or filters as suggested in https://github.com/scipy/scipy/pull/4312#issuecomment-75699528 this would be cool.



Discussion:
note that the comment linked above has the pattern to use. More examples can easily be found by searching the tests for use of `warnings`

preferably this should be done before the next release branch is created.


Resolving patch:
diff --git a/scipy/optimize/optimize.py b/scipy/optimize/optimize.py
--- a/scipy/optimize/optimize.py
+++ b/scipy/optimize/optimize.py
@@ -35,7 +35,8 @@
                    vectorize, asarray, sqrt, Inf, asfarray, isinf)
 import numpy as np
 from .linesearch import (line_search_wolfe1, line_search_wolfe2,
-                         line_search_wolfe2 as line_search)
+                         line_search_wolfe2 as line_search,
+                         LineSearchWarning)
 
 
 # standard status messages of optimizers
@@ -693,8 +694,10 @@ def _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval,
 
     if ret[0] is None:
         # line search failed: try different one.
-        ret = line_search_wolfe2(f, fprime, xk, pk, gfk,
-                                 old_fval, old_old_fval)
+        with warnings.catch_warnings():
+            warnings.simplefilter('ignore', LineSearchWarning)
+            ret = line_search_wolfe2(f, fprime, xk, pk, gfk,
+                                     old_fval, old_old_fval)
 
     if ret[0] is None:
         raise _LineSearchError()


Test patch:
diff --git a/scipy/optimize/tests/test_linesearch.py b/scipy/optimize/tests/test_linesearch.py
--- a/scipy/optimize/tests/test_linesearch.py
+++ b/scipy/optimize/tests/test_linesearch.py
@@ -3,9 +3,12 @@
 """
 from __future__ import division, print_function, absolute_import
 
+import warnings
+
 from numpy.testing import assert_, assert_equal, \
      assert_array_almost_equal, assert_array_almost_equal_nulp
 import scipy.optimize.linesearch as ls
+from scipy.optimize.linesearch import LineSearchWarning
 import numpy as np
 
 
@@ -190,9 +193,11 @@ def test_line_search_wolfe2(self):
             f0 = f(x)
             g0 = fprime(x)
             self.fcount = 0
-            s, fc, gc, fv, ofv, gv = ls.line_search_wolfe2(f, fprime, x, p,
-                                                           g0, f0, old_f,
-                                                           amax=smax)
+            with warnings.catch_warnings():
+                warnings.simplefilter('ignore', LineSearchWarning)
+                s, fc, gc, fv, ofv, gv = ls.line_search_wolfe2(f, fprime, x, p,
+                                                               g0, f0, old_f,
+                                                               amax=smax)
             assert_equal(self.fcount, fc+gc)
             assert_fp_equal(ofv, f(x))
             assert_fp_equal(fv, f(x + s*p))
diff --git a/scipy/optimize/tests/test_optimize.py b/scipy/optimize/tests/test_optimize.py
--- a/scipy/optimize/tests/test_optimize.py
+++ b/scipy/optimize/tests/test_optimize.py
@@ -527,9 +527,9 @@ def dfunc(z):
             else:
                 jac = dfunc
 
-            sol1 = optimize.minimize(func, [1,1], jac=jac, tol=1e-10,
+            sol1 = optimize.minimize(func, [1, 1], jac=jac, tol=1e-10,
                                      method=method)
-            sol2 = optimize.minimize(func, [1,1], jac=jac, tol=1.0,
+            sol2 = optimize.minimize(func, [1, 1], jac=jac, tol=1.0,
                                      method=method)
             assert_(func(sol1.x) < func(sol2.x),
                     "%s: %s vs. %s" % (method, func(sol1.x), func(sol2.x)))
@@ -915,4 +915,3 @@ def test_attributes_present(self):
 
 if __name__ == "__main__":
     run_module_suite()
-