BUG: `optimize.curve_fit` with `nan_policy="omit"` fails to handle sigma properly
### Describe your issue.

Hello,
I have encountered an issue with curve_fit. It is bypassable, but I'd say it is unexpected behaviour. Generally speaking, it occurs when both of the following is true:
-- I have xdata or ydata with NaNs and use nan_policy = "omit" to handle them;
-- I have specified sigma.
In this case, I get ValueError "Sigma has incorrect shape" in optimize._minpack_py.py despite sigma being of the same size as xdata and ydata.

I checked what is going in _minpack_py.py and figured out the following.
It occurs because "nan_policy = omit" leads to the removal of NaN indices from xdata and ydata (lines 960-967), but not from sigma. Then, after line 969, the shape of sigma is checked by comparing it with ydata. And even if sigma and ydata were originally of the same size, they end up to be different after ydata truncation, throwing an error.

So, to bypass this problem, one has either to remove indices corresponding NaNs in xdata and ydata from sigma, or not using nan_policy = "omit" at all and remove NaN indices manually. I suggest improving nan_policy = "omit" in a way that it would remove the corresponding indices from sigma, if needed.

Sorry if my bug report is incorrect, I am first time doing this.

### Reproducing Code Example

```python
import numpy as np
from scipy.optimize import curve_fit

def exponential(x, a, b):
	return b * np.exp(a * x)

np.random.seed(0)
N = 90
x = np.linspace(1, 10, N, endpoint = False)
sigma = x * 0.05
y = exponential(x, 0.2, 0.5) + np.random.normal(0, sigma, N)

p0 = [0.1, 1.0]

# without nans, works perfect
popt, pcov = curve_fit(exponential, x, y, p0 = p0, sigma = sigma)
perr = np.diag(np.sqrt(pcov))
print("without nans:")
print(f"popt: {popt}")
print(f"perr: {perr}")

# with nans, have to set nan_policy = "omit"...
x[11] = np.nan
y[22] = np.nan
popt, pcov = curve_fit(exponential, x, y, p0 = p0, nan_policy = "omit")
perr = np.diag(np.sqrt(pcov))
print("with nans:")
print(f"popt: {popt}")
print(f"perr: {perr}")

#...but when using sigma, it says "sigma has incorrect shape"
x[11] = np.nan
y[22] = np.nan
popt, pcov = curve_fit(exponential, x, y, p0 = p0, sigma = sigma, nan_policy = "omit")
```


### Error message

```shell
Traceback (most recent call last):
  File "/root/Science/Spiral_shape_analysis/fit_results/../spiralcutter_advanced/scipy_test.py", line 34, in <module>
    popt, pcov = curve_fit(exponential, x, y, p0 = p0, sigma = sigma, nan_policy = "omit")
  File "/usr/local/lib/python3.10/dist-packages/scipy/optimize/_minpack_py.py", line 985, in curve_fit
    raise ValueError("`sigma` has incorrect shape.")
ValueError: `sigma` has incorrect shape.
```


### SciPy/NumPy/Python version and system information

```shell
>>> print(scipy.__version__, numpy.__version__, sys.version_info)
1.14.1 2.1.2 sys.version_info(major=3, minor=10, micro=12, releaselevel='final', serial=0)
>>> scipy.show_config()
Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: /opt/_internal/cpython-3.10.14/lib/python3.10/site-packages/scipy_openblas32/include
    lib directory: /opt/_internal/cpython-3.10.14/lib/python3.10/site-packages/scipy_openblas32/lib
    name: scipy-openblas
    openblas configuration: OpenBLAS 0.3.27.dev DYNAMIC_ARCH NO_AFFINITY Zen MAX_THREADS=64
    pc file directory: /project
    version: 0.3.27.dev
  lapack:
    detection method: pkgconfig
    found: true
    include directory: /opt/_internal/cpython-3.10.14/lib/python3.10/site-packages/scipy_openblas32/include
    lib directory: /opt/_internal/cpython-3.10.14/lib/python3.10/site-packages/scipy_openblas32/lib
    name: scipy-openblas
    openblas configuration: OpenBLAS 0.3.27.dev DYNAMIC_ARCH NO_AFFINITY Zen MAX_THREADS=64
    pc file directory: /project
    version: 0.3.27.dev
  pybind11:
    detection method: config-tool
    include directory: unknown
    name: pybind11
    version: 2.12.0
Compilers:
  c:
    commands: cc
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  c++:
    commands: c++
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 3.0.11
  fortran:
    commands: gfortran
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  pythran:
    include directory: ../../tmp/pip-build-env-h_xz8lfs/overlay/lib/python3.10/site-packages/pythran
    version: 0.16.1
Machine Information:
  build:
    cpu: x86_64
    endian: little
    family: x86_64
    system: linux
  cross-compiled: false
  host:
    cpu: x86_64
    endian: little
    family: x86_64
    system: linux
Python Information:
  path: /opt/python/cp310-cp310/bin/python
  version: '3.10'
```