Repository: scipy/scipy

Issue:
DEP: add deprecation warning to `maxiter` kwarg in `_minimize_tnc`
Deprecated in documentation only in https://github.com/scipy/scipy/pull/11526

Since this is happening in the private method `_minimize_tnc` (and the wrapper `fmin_tnc` doesn't seem to use `maxiter` anymore), it might be possible to remove this outright.

CC @AtsushiSakai 


Discussion:

Resolving patch:
diff --git a/scipy/optimize/_tnc.py b/scipy/optimize/_tnc.py
--- a/scipy/optimize/_tnc.py
+++ b/scipy/optimize/_tnc.py
@@ -32,6 +32,8 @@
 (as a list of values); or None, to abort the minimization.
 """
 
+import warnings
+
 from scipy.optimize import _moduleTNC as moduleTNC
 from ._optimize import (MemoizeJac, OptimizeResult, _check_unknown_options,
                        _prepare_scalar_function)
@@ -312,7 +314,8 @@ def _minimize_tnc(fun, x0, args=(), jac=None, bounds=None,
         max(1,min(50,n/2)). Defaults to -1.
     maxiter : int, optional
         Maximum number of function evaluations. This keyword is deprecated
-        in favor of `maxfun`. Only if `maxfun` is None is this keyword used.
+        in favor of `maxfun` and will removed in SciPy 1.11.0.
+        Default is None.
     eta : float
         Severity of the line search. If < 0 or > 1, set to 0.25.
         Defaults to -1.
@@ -409,6 +412,11 @@ def _minimize_tnc(fun, x0, args=(), jac=None, bounds=None,
 
     if maxfun is None:
         if maxiter is not None:
+            warnings.warn(
+                "'maxiter' has been deprecated in favor of 'maxfun'"
+                " and will be removed in SciPy 1.11.0.",
+                DeprecationWarning, stacklevel=3
+            )
             maxfun = maxiter
         else:
             maxfun = max(100, 10*len(x0))


Test patch:
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
@@ -1186,8 +1186,10 @@ def bad_grad(x):
         jac = bad_grad
         if method in ['nelder-mead', 'powell', 'cobyla']:
             jac = None
-        sol = optimize.minimize(func, x0, jac=jac, method=method,
-                                options=dict(maxiter=20))
+        with suppress_warnings() as sup:
+            sup.filter(DeprecationWarning, "'maxiter' has been deprecated...")
+            sol = optimize.minimize(func, x0, jac=jac, method=method,
+                                    options=dict(maxiter=20))
         assert_equal(func(sol.x), sol.fun)
 
         if method == 'slsqp':
@@ -1408,6 +1410,7 @@ def hess(x):
             sup.filter(UserWarning, "delta_grad == 0.*")
             sup.filter(RuntimeWarning, ".*does not use Hessian.*")
             sup.filter(RuntimeWarning, ".*does not use gradient.*")
+            sup.filter(DeprecationWarning, "'maxiter' has been deprecated...")
 
             for f, g, h in itertools.product(funcs, grads, hesss):
                 count = [0]
@@ -1721,6 +1724,7 @@ def func(x):
             sup.filter(UserWarning, "delta_grad == 0.*")
             sup.filter(RuntimeWarning, ".*does not use Hessian.*")
             sup.filter(RuntimeWarning, ".*does not use gradient.*")
+            sup.filter(DeprecationWarning, "'maxiter' has been deprecated...")
 
             count = [0]
             sol = optimize.minimize_scalar(func, bracket=bracket,
diff --git a/scipy/optimize/tests/test_tnc.py b/scipy/optimize/tests/test_tnc.py
--- a/scipy/optimize/tests/test_tnc.py
+++ b/scipy/optimize/tests/test_tnc.py
@@ -346,3 +346,10 @@ def callback(x):
         assert_allclose(res2.x, res.x)
         assert_allclose(res2.fun, res.fun)
         assert_equal(res2.nfev, res.nfev)
+
+    def test_maxiter_depreciations(self):
+        msg = "'maxiter' has been deprecated in favor of 'maxfun'"
+        with pytest.warns(DeprecationWarning, match=msg):
+            optimize.minimize(
+                self.f1, [1, 3], method="TNC", options={"maxiter": 1}
+            )