Repository: scipy/scipy

Issue:
least_squares ValueError with 'lm' method - regression from 1.4.1 -> 1.5.0
<!-- 
Thank you for taking the time to file a bug report. 
Please fill in the fields below, deleting the sections that 
don't apply to your issue. You can view the final output
by clicking the preview button above.
Note: This is a comment, and won't appear in the output.
-->

When setting `ftol=None` the least_squares function throws a `ValueError`. According to the docs `None` is a valid value: 
> If None, the termination by this condition is disabled.

The problem was probably introduced with #11741

#### Reproducing code example:
```
least_squares( error_func, par, verbose=0, method="lm", ftol=None)
```

#### Error message:
<!-- If any, paste the *full* error message inside a code block
as above (starting from line Traceback)
-->

```
.tox\python\lib\site-packages\scipy\optimize\_lsq\least_squares.py:799: in least_squares
    ftol, xtol, gtol = check_tolerance(ftol, xtol, gtol, method)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

ftol = 0, xtol = 1e-08, gtol = 1e-08, method = 'lm'

    def check_tolerance(ftol, xtol, gtol, method):
        def check(tol, name):
            if tol is None:
                tol = 0
            elif tol < EPS:
                warn("Setting `{}` below the machine epsilon ({:.2e}) effectively "
                     "disables the corresponding termination condition."
                     .format(name, EPS))
            return tol

        ftol = check(ftol, "ftol")
        xtol = check(xtol, "xtol")
        gtol = check(gtol, "gtol")

        if method == "lm" and (ftol < EPS or xtol < EPS or gtol < EPS):
>           raise ValueError("All tolerances must be higher than machine epsilon "
E           ValueError: All tolerances must be higher than machine epsilon (2.22e-16) for method 'lm'.

```

#### Scipy/Numpy/Python version information:
scipy==1.5.0
numpy==1.19.0
 


Discussion:
It is desired behavior for method 'lm'. Without it minpack might fail and we have to handle its error somehow. We decided to handle it this way. 

Our mistake is that it wasn't mentioned in the release notes and the documentation is probably insufficient.

Would you be interested in updating documentation for parameters `ftol`, `xtol` and `gtol`?

Resolving patch:
diff --git a/scipy/optimize/_lsq/least_squares.py b/scipy/optimize/_lsq/least_squares.py
--- a/scipy/optimize/_lsq/least_squares.py
+++ b/scipy/optimize/_lsq/least_squares.py
@@ -304,8 +304,11 @@ def least_squares(
         Tolerance for termination by the change of the cost function. Default
         is 1e-8. The optimization process is stopped when ``dF < ftol * F``,
         and there was an adequate agreement between a local quadratic model and
-        the true model in the last step. If None, the termination by this
-        condition is disabled.
+        the true model in the last step.
+
+        If None and 'method' is not 'lm', the termination by this condition is
+        disabled. If 'method' is 'lm', this tolerance must be higher than
+        machine epsilon.
     xtol : float or None, optional
         Tolerance for termination by the change of the independent variables.
         Default is 1e-8. The exact condition depends on the `method` used:
@@ -315,7 +318,9 @@ def least_squares(
               a trust-region radius and ``xs`` is the value of ``x``
               scaled according to `x_scale` parameter (see below).
 
-        If None, the termination by this condition is disabled.
+        If None and 'method' is not 'lm', the termination by this condition is
+        disabled. If 'method' is 'lm', this tolerance must be higher than
+        machine epsilon.
     gtol : float or None, optional
         Tolerance for termination by the norm of the gradient. Default is 1e-8.
         The exact condition depends on a `method` used:
@@ -330,7 +335,9 @@ def least_squares(
               between columns of the Jacobian and the residual vector is less
               than `gtol`, or the residual vector is zero.
 
-        If None, the termination by this condition is disabled.
+        If None and 'method' is not 'lm', the termination by this condition is
+        disabled. If 'method' is 'lm', this tolerance must be higher than
+        machine epsilon.
     x_scale : array_like or 'jac', optional
         Characteristic scale of each variable. Setting `x_scale` is equivalent
         to reformulating the problem in scaled variables ``xs = x / x_scale``.


Test patch: