internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: scipy/scipy

Issue:
Pearson's original paper on chi-square test could be referenced.
I often work with chi-square tests and found it surprising that Pearson's paper wasn't found among the references. Is this something we can add?


Discussion:

Resolving patch:
diff --git a/scipy/stats/stats.py b/scipy/stats/stats.py
--- a/scipy/stats/stats.py
+++ b/scipy/stats/stats.py
@@ -6545,12 +6545,18 @@ def chisquare(f_obs, f_exp=None, ddof=0, axis=0):
     See Also
     --------
     scipy.stats.power_divergence
+    scipy.stats.fisher_exact : A more powerful alternative to the chisquare
+                               test if any of the frequencies are less than 5.
 
     Notes
     -----
     This test is invalid when the observed or expected frequencies in each
     category are too small.  A typical rule is that all of the observed
-    and expected frequencies should be at least 5.
+    and expected frequencies should be at least 5. If one or more frequencies
+    are less than 5, Fisher's Exact Test can be used with greater statistical
+    power. According to [3]_, the total number of samples is recommended to be
+    greater than 13, otherwise a table-based method of obtaining p-values is 
+    recommended.
 
     Also, the sum of the observed and expected frequencies must be the same
     for the test to be valid; `chisquare` raises an error if the sums do not
@@ -6570,6 +6576,10 @@ def chisquare(f_obs, f_exp=None, ddof=0, axis=0):
            Statistics". Chapter 8.
            https://web.archive.org/web/20171022032306/http://vassarstats.net:80/textbook/ch8pt1.html
     .. [2] "Chi-squared test", https://en.wikipedia.org/wiki/Chi-squared_test
+    .. [3] Pearson, Karl. "On the criterion that a given system of deviations from the probable 
+           in the case of a correlated system of variables is such that it can be reasonably 
+           supposed to have arisen from random sampling", Philosophical Magazine. Series 5. 50
+           (1900), pp. 157-175.
 
     Examples
     --------


Test patch:
Repository: scipy/scipy

Issue:
The use of starred expressions to create data detracts from understanding required data structure 
https://github.com/scipy/scipy/blob/01d8bfb6f239df4ce70c799b9b485b53733c9911/scipy/interpolate/interpolate.py#L2369

Starred expressions can't be readily examined. For users who are attempting to familiarize themselves with the required data structures for RegularGridInterpolator, it adds unnecessary additional complexity.

I would suggest creating the meshgrid outside of the function call so that the purpose of the starred expression is more easily understood.

Despite the description of the structure of ```data``` below, it is difficult to adapt to unique user use cases. 


Discussion:
PR welcome
Great - I will start taking a look. 

Resolving patch:
diff --git a/scipy/interpolate/interpolate.py b/scipy/interpolate/interpolate.py
--- a/scipy/interpolate/interpolate.py
+++ b/scipy/interpolate/interpolate.py
@@ -2400,7 +2400,8 @@ class RegularGridInterpolator:
     >>> x = np.linspace(1, 4, 11)
     >>> y = np.linspace(4, 7, 22)
     >>> z = np.linspace(7, 9, 33)
-    >>> data = f(*np.meshgrid(x, y, z, indexing='ij', sparse=True))
+    >>> xg, yg ,zg = np.meshgrid(x, y, z, indexing='ij', sparse=True)
+    >>> data = f(xg, yg, zg)
 
     ``data`` is now a 3-D array with ``data[i,j,k] = f(x[i], y[j], z[k])``.
     Next, define an interpolating function from this data:


Test patch:
Repository: scipy/scipy

Issue:
MAINT: optimize: `curve_fit` input error msg can be improved.
The `curve_fit` doc says:
https://github.com/scipy/scipy/blob/4ec4ab8d6ccc1cdb34b84fdcb66fde2cc0210dbf/scipy/optimize/minpack.py#L601-L602

But, in this case, the error message is unclear (this msg was improved in #13990 though).

```
def func(x, a, b, c, d, e):
            return a * np.exp(-b * x) + c + d + e

curve_fit(func,
          xdata=[1, 2, 3, 4],
          ydata=[5, 9, 13, 17])

TypeError: Improper input: func input vector length N=5 must not exceed func output vector length M=4
```
Because, the error msg from `leastsq`, not `curve_fit`. The `func` is not the user defined one, is `leastsq`'s one.
I think some beginners might confuse the message like #13969, the message can be improved.



Discussion:

Resolving patch:
diff --git a/scipy/optimize/minpack.py b/scipy/optimize/minpack.py
--- a/scipy/optimize/minpack.py
+++ b/scipy/optimize/minpack.py
@@ -780,6 +780,10 @@ def curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False,
         raise ValueError("'args' is not a supported keyword argument.")
 
     if method == 'lm':
+        # if ydata.size == 1, this might be used for broadcast.
+        if ydata.size != 1 and n > ydata.size:
+            raise TypeError(f"The number of func parameters={n} must not"
+                            f" exceed the number of data points={ydata.size}")
         # Remove full_output from kwargs, otherwise we're passing it in twice.
         return_full = kwargs.pop('full_output', False)
         res = leastsq(func, p0, Dfun=jac, full_output=1, **kwargs)


Test patch:
diff --git a/scipy/optimize/tests/test_minpack.py b/scipy/optimize/tests/test_minpack.py
--- a/scipy/optimize/tests/test_minpack.py
+++ b/scipy/optimize/tests/test_minpack.py
@@ -812,6 +812,15 @@ def func(x, a, b):
                       p0=[1],
                       args=(1,))
 
+    def test_data_point_number_validation(self):
+        def func(x, a, b, c, d, e):
+            return a * np.exp(-b * x) + c + d + e
+
+        with assert_raises(TypeError, match="The number of func parameters="):
+            curve_fit(func,
+                      xdata=[1, 2, 3, 4],
+                      ydata=[5, 9, 13, 17])
+
 
 class TestFixedPoint:
Repository: scipy/scipy

Issue:
MAINT: pavement.py PYVER is outdated
It hasn't affected me so far, but since we've dropped Python `3.6` support I imagine this entry in `pavement.py` may need an update:

```python
# Default Python version  
PYVER="3.6" 
```

I suppose if I run into issues I can temporarily bump it pending a backport fix after the release.


Discussion:
Hey, can I bump it and make a PR considering we aren't supporting Python 3.6 anymore
@tylerjereddy you can change it permanently to whatever is your default Python version. It doesn't really matter. We use very little of what's in `pavement.py`, we should just do whatever is easiest until we build _all_ release artifacts in the `scipy-wheels` CI and then get rid of `pavement.py` completely.

Resolving patch:
diff --git a/pavement.py b/pavement.py
--- a/pavement.py
+++ b/pavement.py
@@ -81,7 +81,7 @@
 #-------------------------------------------------------
 
 # Default Python version
-PYVER="3.6"
+PYVER="3.9"
 
 # Paver options object, holds all default dirs
 options(bootstrap=Bunch(bootstrap_dir="bootstrap"),


Test patch:
Repository: scipy/scipy

Issue:
DOC: Inconsistency in the definition of default values in the model `UnivariateSpline`
<!-- 
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.
-->

My issue is about  inconsistency in the definition of default values in the model `UnivariateSpline`
ttps://github.com/scipy/scipy/blob/4ec4ab8d6ccc1cdb34b84fdcb66fde2cc0210dbf/scipy/interpolate/fitpack2.py#L71

Sometimes the default value is defined in brackets (), sometimes at the end of the docstring.

#### Reproducing code example:
<!-- 
If you place your code between the triple backticks below, 
it will be rendered as a code block. 
-->

https://github.com/scipy/scipy/blob/4ec4ab8d6ccc1cdb34b84fdcb66fde2cc0210dbf/scipy/interpolate/fitpack2.py#L80-L119


#### Scipy/Numpy/Python version information:


Current release: 1.6.3


Discussion:

Resolving patch:
diff --git a/scipy/interpolate/fitpack2.py b/scipy/interpolate/fitpack2.py
--- a/scipy/interpolate/fitpack2.py
+++ b/scipy/interpolate/fitpack2.py
@@ -83,23 +83,23 @@ class UnivariateSpline:
     y : (N,) array_like
         1-D array of dependent input data, of the same length as `x`.
     w : (N,) array_like, optional
-        Weights for spline fitting.  Must be positive.  If None (default),
-        weights are all equal.
+        Weights for spline fitting.  Must be positive.  If `w` is None,
+        weights are all equal. Default is None.
     bbox : (2,) array_like, optional
         2-sequence specifying the boundary of the approximation interval. If
-        None (default), ``bbox=[x[0], x[-1]]``.
+        `bbox` is None, ``bbox=[x[0], x[-1]]``. Default is None.
     k : int, optional
         Degree of the smoothing spline.  Must be 1 <= `k` <= 5.
-        Default is `k` = 3, a cubic spline.
+        ``k = 3`` is a cubic spline. Default is 3.
     s : float or None, optional
         Positive smoothing factor used to choose the number of knots.  Number
         of knots will be increased until the smoothing condition is satisfied::
 
             sum((w[i] * (y[i]-spl(x[i])))**2, axis=0) <= s
 
-        If None (default), ``s = len(w)`` which should be a good value if
+        If `s` is None, ``s = len(w)`` which should be a good value if
         ``1/w[i]`` is an estimate of the standard deviation of ``y[i]``.
-        If 0, spline will interpolate through all data points.
+        If 0, spline will interpolate through all data points. Default is None.
     ext : int or str, optional
         Controls the extrapolation mode for elements
         not in the interval defined by the knot sequence.
@@ -109,7 +109,7 @@ class UnivariateSpline:
         * if ext=2 or 'raise', raise a ValueError
         * if ext=3 of 'const', return the boundary value.
 
-        The default value is 0.
+        Default is 0.
 
     check_finite : bool, optional
         Whether to check that the input arrays contain only finite numbers.


Test patch:
Repository: scipy/scipy

Issue:
DOC: Add example as to how to use solve_ivp to solve complex matrix differential equations
**Is your feature request related to a problem? Please describe.**
No. 
The example given in the documentation does not make it easy to 
guess the way to use solve_ivp to solve complex matrix differential equations.

**Describe the solution you'd like**
Add a sufficiently  detailed example

**Describe alternatives you've considered**
[example ](https://www.dropbox.com/s/ip1fqko2f7xfs41/patol75_answer_pristine_only_matrix.ipynb?dl=0) based on [this answer](https://stackoverflow.com/a/65838993/7952027) to this [question](https://stackoverflow.com/q/65793457/7952027)

**Additional context (e.g. screenshots)**



Discussion:

Resolving patch:
diff --git a/scipy/integrate/_ivp/ivp.py b/scipy/integrate/_ivp/ivp.py
--- a/scipy/integrate/_ivp/ivp.py
+++ b/scipy/integrate/_ivp/ivp.py
@@ -520,6 +520,49 @@ def solve_ivp(fun, t_span, y0, method='RK45', t_eval=None, dense_output=False,
     >>> plt.title('Lotka-Volterra System')
     >>> plt.show()
 
+    A couple examples of using solve_ivp to solve the differential
+    equation ``y' = Ay`` with complex matrix ``A``.
+
+    >>> A = np.array([[-0.25 + 0.14j, 0, 0.33 + 0.44j],
+    ...               [0.25 + 0.58j, -0.2 + 0.14j, 0],
+    ...               [0, 0.2 + 0.4j, -0.1 + 0.97j]])
+
+    Solving an IVP with ``A`` from above and ``y`` as 3x1 vector:
+
+    >>> def deriv_vec(t, y):
+    ...     return A @ y
+    >>> result = solve_ivp(deriv_vec, [0, 25],
+    ...                    np.array([10 + 0j, 20 + 0j, 30 + 0j]),
+    ...                    t_eval=np.linspace(0, 25, 101))
+    >>> print(result.y[:, 0])
+    [10.+0.j 20.+0.j 30.+0.j]
+    >>> print(result.y[:, -1])
+    [18.46291039+45.25653651j 10.01569306+36.23293216j
+     -4.98662741+80.07360388j]
+
+    Solving an IVP with ``A`` from above with ``y`` as 3x3 matrix :
+
+    >>> def deriv_mat(t, y):
+    ...     return (A @ y.reshape(3, 3)).flatten()
+    >>> y0 = np.array([[2 + 0j, 3 + 0j, 4 + 0j],
+    ...                [5 + 0j, 6 + 0j, 7 + 0j],
+    ...                [9 + 0j, 34 + 0j, 78 + 0j]])
+
+    >>> result = solve_ivp(deriv_mat, [0, 25], y0.flatten(),
+    ...                    t_eval=np.linspace(0, 25, 101))
+    >>> print(result.y[:, 0].reshape(3, 3))
+    [[ 2.+0.j  3.+0.j  4.+0.j]
+     [ 5.+0.j  6.+0.j  7.+0.j]
+     [ 9.+0.j 34.+0.j 78.+0.j]]
+    >>> print(result.y[:, -1].reshape(3, 3))
+    [[  5.67451179 +12.07938445j  17.2888073  +31.03278837j
+        37.83405768 +63.25138759j]
+     [  3.39949503 +11.82123994j  21.32530996 +44.88668871j
+        53.17531184+103.80400411j]
+     [ -2.26105874 +22.19277664j -15.1255713  +70.19616341j
+       -38.34616845+153.29039931j]]
+
+
     """
     if method not in METHODS and not (
             inspect.isclass(method) and issubclass(method, OdeSolver)):


Test patch:
Repository: scipy/scipy

Issue:
MAINT: download-wheels.py missing import
It only affects 1 person really--traceback and patch that fixes are below. I'll deal with it after the release process today if I can.

`python tools/download-wheels.py 1.7.0rc1 -w /home/tyler/github_projects/scipy/release/installers/`

```python
Traceback (most recent call last):
  File "/home/tyler/github_projects/scipy/tools/download-wheels.py", line 102, in <module>
    download_wheels(args.version, wheelhouse)
  File "/home/tyler/github_projects/scipy/tools/download-wheels.py", line 70, in download_wheels
    http = http_manager()
  File "/home/tyler/github_projects/scipy/tools/download-wheels.py", line 27, in http_manager
    proxy_dict = urllib.request.getproxies()
AttributeError: module 'urllib' has no attribute 'request'
```

The fix:

```diff
diff --git a/tools/download-wheels.py b/tools/download-wheels.py
index a02b69bbd..4def76b56 100644
--- a/tools/download-wheels.py
+++ b/tools/download-wheels.py
@@ -9,6 +9,7 @@ import re
 import shutil
 import argparse
 import urllib
+import urllib.request
 
 import urllib3
 from bs4 import BeautifulSoup
```


Discussion:

Resolving patch:
diff --git a/tools/download-wheels.py b/tools/download-wheels.py
--- a/tools/download-wheels.py
+++ b/tools/download-wheels.py
@@ -9,6 +9,7 @@
 import shutil
 import argparse
 import urllib
+import urllib.request
 
 import urllib3
 from bs4 import BeautifulSoup


Test patch:
Repository: scipy/scipy

Issue:
Missing "inverse" word in the multidimensional Discrete Cosine/Sine Transforms documentation
In https://docs.scipy.org/doc/scipy/reference/fft.html and inside idctn and idstn documents both methods are described as multidimensional Discrete Cosine/Sine Transforms instead of multidimensional inverse Discrete Cosine/Sine Transforms.


Discussion:
Hello @tupui , can you assign me this issue ?

@FallenApart , this is required `multidimensional Discrete Cosine/Sine Transforms` to `multidimensional inverse Discrete Cosine/Sine Transforms` right ?

HI @kadatatlukishore, in our workflow we don't assign issues. It's enough to say here that you are working on this. Just check before on open PRs that someone is not working on it and did not say anything here (which they should). So feel free to propose something, you can also co-author some commits with @FallenApart. As you both wish 😃
Thanks for the clarification @tupui and I've checked there is no open PR for this. Will start working on this, thanks again !

Resolving patch:
diff --git a/scipy/fft/_realtransforms.py b/scipy/fft/_realtransforms.py
--- a/scipy/fft/_realtransforms.py
+++ b/scipy/fft/_realtransforms.py
@@ -68,7 +68,7 @@ def dctn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False,
 def idctn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False,
           workers=None):
     """
-    Return multidimensional Discrete Cosine Transform along the specified axes.
+    Return multidimensional Inverse Discrete Cosine Transform along the specified axes.
 
     Parameters
     ----------
@@ -186,7 +186,7 @@ def dstn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False,
 def idstn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False,
           workers=None):
     """
-    Return multidimensional Discrete Sine Transform along the specified axes.
+    Return multidimensional Inverse Discrete Sine Transform along the specified axes.
 
     Parameters
     ----------


Test patch:
Repository: scipy/scipy

Issue:
BUG: scipy.stats.multivariate_t distribution math documentation
### Reproducing Code Example

```python
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.multivariate_t.html#scipy.stats.multivariate_t

the math formula for the probability density function contains an extraneous exp. See the multivariate t-distribution wikipedia page at https://en.wikipedia.org/wiki/Multivariate_t-distribution
```


### Error message

```shell
No error message
```


### SciPy/NumPy/Python version information

1.7.1 documentation 


Discussion:
That does seem like an error in documentation. Thanks for reporting! Would you like to submit a pull request?

Resolving patch:
diff --git a/scipy/stats/_multivariate.py b/scipy/stats/_multivariate.py
--- a/scipy/stats/_multivariate.py
+++ b/scipy/stats/_multivariate.py
@@ -3879,7 +3879,7 @@ class multivariate_t_gen(multi_rv_generic):
     .. math::
 
         f(x) = \frac{\Gamma(\nu + p)/2}{\Gamma(\nu/2)\nu^{p/2}\pi^{p/2}|\Sigma|^{1/2}}
-               \exp\left[1 + \frac{1}{\nu} (\mathbf{x} - \boldsymbol{\mu})^{\top}
+               \left[1 + \frac{1}{\nu} (\mathbf{x} - \boldsymbol{\mu})^{\top}
                \boldsymbol{\Sigma}^{-1}
                (\mathbf{x} - \boldsymbol{\mu}) \right]^{-(\nu + p)/2},
 


Test patch:
Repository: scipy/scipy

Issue:
ENH: get the driver used in scipy.linalg.eigh
We are seeing a CPU-specific [error](https://trac.sagemath.org/ticket/31621) while calling `scipy.linalg.eigh` without `driver=` set.
In this case, `driver` is chosen automatically, but it's very hard to figure out which one is used
[The scipy docs](https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html) talk at length about the relative
merits of different LAPACK drivers, but still leave one wondering which one is used by default. It says
```
As a brief summary, the slowest and the most robust driver is the classical <sy/he>ev which uses symmetric QR. 
<sy/he>evr is seen as the optimal choice for the most general cases. However, there are certain occasions that 
<sy/he>evd computes faster at the expense of more memory usage. <sy/he>evx, while still being faster than 
<sy/he>ev, often performs worse than the rest except when very few eigenvalues are requested...
```



### Describe the solution you'd like.

Either document the `driver` choice sufficiently, or provide a way to find the choice out. E.g. a mode of operation where the driver choice is a part of the data returned.

### Describe alternatives you've considered.

_No response_

### Additional context (e.g. screenshots, GIFs)

_No response_


Discussion:
Depends on the given keywords; if no subsets are required then default driver is `evr` and `gvd`. If subsets are requested then `gvx` for generalized problems. 

https://github.com/scipy/scipy/blob/v1.7.1/scipy/linalg/decomp.py#L521

I'll add it to the docs. 
In regard of `evr` - it takes `ABSTOL` as a parameter, but there is nothing in SciPy doc on this. Is `ABSTOL=0` used here?
Yes when omitted LAPACK uses `eps*norm(T, 1)` as the tolerance value where T is the tridiagonalized input array. For custom input values, users can call the underlying lapack routine via `scipy.linalg.lapack` module. In this case https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.lapack.dsyevr.html or other data type flavors.

Resolving patch:
diff --git a/scipy/linalg/_decomp.py b/scipy/linalg/_decomp.py
--- a/scipy/linalg/_decomp.py
+++ b/scipy/linalg/_decomp.py
@@ -313,6 +313,8 @@ def eigh(a, b=None, lower=True, eigvals_only=False, overwrite_a=False,
         Defines which LAPACK driver should be used. Valid options are "ev",
         "evd", "evr", "evx" for standard problems and "gv", "gvd", "gvx" for
         generalized (where b is not None) problems. See the Notes section.
+        The default for standard problems is "evr". For generalized problems,
+        "gvd" is used for full set, and "gvx" for subset requested cases.
     type : int, optional
         For the generalized problems, this keyword specifies the problem type
         to be solved for ``w`` and ``v`` (only takes 1, 2, 3 as possible


Test patch:
Repository: scipy/scipy

Issue:
DOC: `directed_hausdorff` expects 2D array despite docs stating N-D
### Describe your issue.

If we look at the docs for directed_hausdorff (https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.directed_hausdorff.html) it states "Compute the directed Hausdorff distance between two N-D arrays."

However when attempting to feed it two 3-D arrays it errors with 
```
File "[...]/scipy/spatial/distance.py", line 450, in directed_hausdorff
    result = _hausdorff.directed_hausdorff(u, v, seed)
  File "_hausdorff.pyx", line 21, in scipy.spatial._hausdorff.directed_hausdorff
ValueError: Buffer has wrong number of dimensions (expected 2, got 3)
```

I am not certain if this is then a bug within the code, or if the docs are simply incorrect and should state 2-D arrays and not N-D arrays.

My code is run on scipy 1.5.2, but as far as I can tell, no change for this has been done up to current master.

### Reproducing Code Example

```python
import numpy as np
from scipy.spatial.distance import directed_hausdorff

a = np.zeros((4, 4, 4))
directed_hausdorff(a, a)
```


### Error message

```shell
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/python3.6/site-packages/scipy/spatial/distance.py", line 450, in directed_hausdorff
    result = _hausdorff.directed_hausdorff(u, v, seed)
  File "_hausdorff.pyx", line 21, in scipy.spatial._hausdorff.directed_hausdorff
ValueError: Buffer has wrong number of dimensions (expected 2, got 3)
```


### SciPy/NumPy/Python version information

1.5.2 1.19.2 sys.version_info(major=3, minor=6, micro=9, releaselevel='final', serial=0)


Discussion:

Resolving patch:
diff --git a/scipy/spatial/distance.py b/scipy/spatial/distance.py
--- a/scipy/spatial/distance.py
+++ b/scipy/spatial/distance.py
@@ -337,7 +337,7 @@ def _validate_wminkowski_kwargs(X, m, n, **kwargs):
 
 def directed_hausdorff(u, v, seed=0):
     """
-    Compute the directed Hausdorff distance between two N-D arrays.
+    Compute the directed Hausdorff distance between two 2-D arrays.
 
     Distances between pairs are calculated using a Euclidean metric.
 


Test patch: