Repository: scipy/scipy

Issue:
curve_fit algorithm try to transform xdata in an array of floats
Hello everyone, 
i recently upgraded to scipy = 1.5.0 and I do not manage to use curve_fit with a particular callable function I wrote anymore. 
The problem resides in the fact that curve_fit tries to transform "xdata" into an array of floats, even if the docs say explicitly that "xdata could be any object". 

The source of error comes from the lines 710 in minpack.py:
   
https://github.com/scipy/scipy/blob/8692c887ac341ace4183f115c55290ec9daf470b/scipy/optimize/minpack.py#L738-L744

Notice also the comments, in evident contradiction with the operation of transforming xdata into an array of floats. 
In version 1.2.0 (which worked for me), there was only xdata = np.asarray(xdata), leading to an object type array, capable of managing also xdata composed of floats, strings,... anything that could be passed to the callable function. 

Functions used to perform the fit:

```python
        def FET(self, x, *pars):
            """
            t, T, n, derivative = x
            T_filt = T
            dT = np.gradient(T_filt, t)
            dT_filt = self.lowpassfilter(t, dT, order = 10, fc = 1/600)
            N = len(pars)
            p1 = np.poly1d(pars[: (n+1)])
            p2 = np.poly1d(pars[(n+1) : N+1])
            if derivative:
                f  = p1(T_filt) + dT_filt*p2(T_filt)
            else:
                f  = p1(T_filt)
                
            return f
        
        def fit_FET(self, func, x, y):
            
            order = x[2]
            guess = np.ones(2*(order+1))
            popt,_ = curve_fit(func, x, y, p0 = guess)
            res = y - func(x,*popt)
            return func(x,*popt), res


x_fet = (clockNEW, TNEW, 3, True)
fet, res_fet = SourceSTD.fit_FET(SourceSTD.FET, x_fet, lppmNEW)
```
## Traceback
```
x_fet = (clockNEW, TNEW, 3, True)
fet, res_fet = SourceSTD.fit_FET(SourceSTD.FET, x_fet, lppmNEW)
TypeError: only size-1 arrays can be converted to Python scalars


The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File "<ipython-input-97-5823eb414f7e>", line 2, in <module>
    fet, res_fet = SourceSTD.fit_FET(SourceSTD.FET, x_fet, lppmNEW)

  File "C:\Users\marco_mancini\Documents\iXBlue\Projects\UMIX\Optical Source\Python\iXOpticalSource\source_utils\main\iXSourceAnalysis.py", line 277, in fit_FET
    popt,_ = curve_fit(func, x, y, p0 = guess, check_finite = False)

  File "C:\Users\marco_mancini\Anaconda3\lib\site-packages\scipy\optimize\minpack.py", line 744, in curve_fit
    xdata = np.asarray(xdata, float)

  File "C:\Users\marco_mancini\Anaconda3\lib\site-packages\numpy\core\_asarray.py", line 85, in asarray
    return array(a, dtype, copy=False, order=order)

ValueError: setting an array element with a sequence.
```








Discussion:

Resolving patch:
diff --git a/scipy/optimize/_minpack_py.py b/scipy/optimize/_minpack_py.py
--- a/scipy/optimize/_minpack_py.py
+++ b/scipy/optimize/_minpack_py.py
@@ -544,10 +544,11 @@ def curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False,
         The model function, f(x, ...). It must take the independent
         variable as the first argument and the parameters to fit as
         separate remaining arguments.
-    xdata : array_like or object
+    xdata : array_like
         The independent variable where the data is measured.
         Should usually be an M-length sequence or an (k,M)-shaped array for
-        functions with k predictors, but can actually be any object.
+        functions with k predictors, and each element should be float
+        convertible if it is an array like object.
     ydata : array_like
         The dependent data, a length M array - nominally ``f(xdata, ...)``.
     p0 : array_like, optional


Test patch: