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

Issue:
Typo in the docstring of simps()
In the definition of the function `simps` under `scipy/integrate/quadrature.py` the docstring says
```
    dx : int, optional
        Spacing of integration points along axis of `y`. Only used when
        `x` is None. Default is 1.
```
`dx` is the spacing along the `x` axis, so the correct formulation should be
```
    dx : int, optional
        Spacing of integration points along axis of `x`. Only used when
        `x` is None. Default is 1.
```


Discussion:
I would like to correct this typo to get familiar with the workflow as I am new to open source.

Resolving patch:
diff --git a/scipy/integrate/quadrature.py b/scipy/integrate/quadrature.py
--- a/scipy/integrate/quadrature.py
+++ b/scipy/integrate/quadrature.py
@@ -393,7 +393,7 @@ def simps(y, x=None, dx=1, axis=-1, even='avg'):
     x : array_like, optional
         If given, the points at which `y` is sampled.
     dx : int, optional
-        Spacing of integration points along axis of `y`. Only used when
+        Spacing of integration points along axis of `x`. Only used when
         `x` is None. Default is 1.
     axis : int, optional
         Axis along which to integrate. Default is the last axis.


Test patch:
Repository: scipy/scipy

Issue:
Documentation missing for what M is in init argument
Is M an initial population of x?


Discussion:
We need some more context for this question.  What `M` are you asking about?
I am referring to the argument 'init' that is passed to differential evolution. Init has M followed by Len(x). So, is M just the initial population of x? What is M in this context? 
For anyone looking for `M`, you can find it in https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html; scroll down to the description of `init` in the *Parameters* section of the docstring.
`M` is the number of individuals in the population. It should be something like `popsize * len(X)`

Resolving patch:
diff --git a/scipy/optimize/_differentialevolution.py b/scipy/optimize/_differentialevolution.py
--- a/scipy/optimize/_differentialevolution.py
+++ b/scipy/optimize/_differentialevolution.py
@@ -125,7 +125,8 @@ def differential_evolution(func, bounds, args=(), strategy='best1bin',
             - 'latinhypercube'
             - 'random'
             - array specifying the initial population. The array should have
-              shape ``(M, len(x))``, where len(x) is the number of parameters.
+              shape ``(M, len(x))``, where M is the total population size and
+              len(x) is the number of parameters.
               `init` is clipped to `bounds` before use.
 
         The default is 'latinhypercube'. Latin Hypercube sampling tries to
@@ -407,7 +408,8 @@ class DifferentialEvolutionSolver(object):
             - 'latinhypercube'
             - 'random'
             - array specifying the initial population. The array should have
-              shape ``(M, len(x))``, where len(x) is the number of parameters.
+              shape ``(M, len(x))``, where M is the total population size and
+              len(x) is the number of parameters.
               `init` is clipped to `bounds` before use.
 
         The default is 'latinhypercube'. Latin Hypercube sampling tries to


Test patch:
Repository: scipy/scipy

Issue:
curve_fit documentation unclear on default value of absolute_sigma
Hello, the [documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html) of the function `scipy.optimize.curve_fit` does not specify that the default value of the parameter `absolute_sigma` is `False`.

It does not seem very intuitive to me that this is the default, but anyway I think it should be specified more clearly in the documentation that this is the case.


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
@@ -575,12 +575,12 @@ def curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False,
         If True, `sigma` is used in an absolute sense and the estimated parameter
         covariance `pcov` reflects these absolute values.
 
-        If False, only the relative magnitudes of the `sigma` values matter.
+        If False (default), only the relative magnitudes of the `sigma` values matter.
         The returned parameter covariance matrix `pcov` is based on scaling
         `sigma` by a constant factor. This constant is set by demanding that the
         reduced `chisq` for the optimal parameters `popt` when using the
         *scaled* `sigma` equals unity. In other words, `sigma` is scaled to
-        match the sample variance of the residuals after the fit.
+        match the sample variance of the residuals after the fit. Default is False.
         Mathematically,
         ``pcov(absolute_sigma=False) = pcov(absolute_sigma=True) * chisq(popt)/(M-N)``
     check_finite : bool, optional


Test patch:
Repository: scipy/scipy

Issue:
scipy.odr.Output.sd_beta is not standard error
<!-- 
Thank you for taking the time to report a SciPy issue.
Please describe the issue in detail, and for bug reports
fill in the fields below. You can delete the sections that 
don't apply to your issue. You can view the final output
by clicking the preview button above.
-->
p(76) of the [ODRPACK documentation](https://docs.scipy.org/doc/external/odrpack_guide.pdfl) says that the square of the diagonal elements of the covariance matrix are the standard deviations not standard error.

I think this is misleading since standard error is the standard deviation scaled by the inverse of the square root of the number of data. 

I suggest the 'sd_beta' attribute be renamed to standard deviation in the doc.




Discussion:

Resolving patch:
diff --git a/scipy/odr/odrpack.py b/scipy/odr/odrpack.py
--- a/scipy/odr/odrpack.py
+++ b/scipy/odr/odrpack.py
@@ -549,7 +549,7 @@ class Output(object):
     beta : ndarray
         Estimated parameter values, of shape (q,).
     sd_beta : ndarray
-        Standard errors of the estimated parameters, of shape (p,).
+        Standard deviations of the estimated parameters, of shape (p,).
     cov_beta : ndarray
         Covariance matrix of the estimated parameters, of shape (p,p).
     delta : ndarray, optional


Test patch:
Repository: scipy/scipy

Issue:
scipy.io.wavfile.write documentation has wrong example
<!-- 
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 the documentation for scipy.io.wavfile.write

The documentation says that this code will 'Create a 100Hz sine wave, sampled at 44100Hz. Write to 16-bit PCM, Mono'

    from scipy.io.wavfile import write
    import numpy as np
    samplerate = 44100; fs = 100
    t = np.linspace(0., 1., samplerate)
    amplitude = np.iinfo(np.int16).max
    data = amplitude * np.sin(2. * np.pi * fs * t)
    write("example.wav", samplerate, data)

On my systems (Windows 10, Python 3.7.7/ Ubuntu 18.04/ Python 3.6.9), it generates a 64 bit float format WAV that audio players do not seem to handle well. Here is the ffprobe output:

    ffprobe example.wav
    Stream #0:0: Audio: pcm_f64le ([3][0][0][0] / 0x0003), 44100 Hz, 1 channels, dbl, 2822 kb/s

To get a 16 bit PCM file with ints in it, I found this worked:

    write("example.wav", samplerate, data.astype(np.int16))

This gives this output with ffprobe:

    ffprobe example.wav
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s




Discussion:

Resolving patch:
diff --git a/scipy/io/wavfile.py b/scipy/io/wavfile.py
--- a/scipy/io/wavfile.py
+++ b/scipy/io/wavfile.py
@@ -691,7 +691,7 @@ def write(filename, rate, data):
     >>> t = np.linspace(0., 1., samplerate)
     >>> amplitude = np.iinfo(np.int16).max
     >>> data = amplitude * np.sin(2. * np.pi * fs * t)
-    >>> write("example.wav", samplerate, data)
+    >>> write("example.wav", samplerate, data.astype(np.int16))
 
     """
     if hasattr(filename, 'write'):


Test patch:
Repository: scipy/scipy

Issue:
integrate.solve_ivp with DOP853 method fails when yDot = 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 the ODE function output is 0, the DOP853 method returns a single point in the solution rather than the full solution. Looks like the method continually refines the step size until it reaches an extremely small number

#### Reproducing code example:
<!-- 
If you place your code between the triple backticks below, 
it will be rendered as a code block. 
-->

```python
sol = integrate.solve_ivp(lambda t, y: np.zeros((3,)), (0, 10), np.ones((3,)), method="DOP853")
print(sol.t)
print(sol.y)
```
changing the lambda to:
```python
lambda t, y: print(t) or np.zeros((3,))
```
shows the issue with the step refinement.

#### Scipy/Numpy/Python version information:

```python
1.4.1 1.18.3 sys.version_info(major=3, minor=6, micro=9, releaselevel='final', serial=0)
```


Discussion:

Resolving patch:
diff --git a/scipy/integrate/_ivp/rk.py b/scipy/integrate/_ivp/rk.py
--- a/scipy/integrate/_ivp/rk.py
+++ b/scipy/integrate/_ivp/rk.py
@@ -495,9 +495,10 @@ def _estimate_error(self, K, h):  # Left for testing purposes.
     def _estimate_error_norm(self, K, h, scale):
         err5 = np.dot(K.T, self.E5) / scale
         err3 = np.dot(K.T, self.E3) / scale
-
         err5_norm_2 = np.sum(err5**2)
         err3_norm_2 = np.sum(err3**2)
+        if err5_norm_2 == 0 and err3_norm_2 == 0:
+            return 0
         denom = err5_norm_2 + 0.01 * err3_norm_2
         return np.abs(h) * err5_norm_2 / np.sqrt(denom * len(scale))
 


Test patch:
diff --git a/scipy/integrate/_ivp/tests/test_ivp.py b/scipy/integrate/_ivp/tests/test_ivp.py
--- a/scipy/integrate/_ivp/tests/test_ivp.py
+++ b/scipy/integrate/_ivp/tests/test_ivp.py
@@ -12,6 +12,10 @@
 from scipy.sparse import coo_matrix, csc_matrix
 
 
+def fun_zero(t, y):
+    return np.zeros_like(y)
+
+
 def fun_linear(t, y):
     return np.array([-y[0] - 5 * y[1], y[0] + y[1]])
 
@@ -968,3 +972,11 @@ def sys3_zfinal(t, w, omega, k, zfinal):
     assert_allclose(y0events[0], np.ones_like(y0events[0]))
     assert_allclose(y0events[1], np.zeros_like(y0events[1]), atol=5e-14)
     assert_allclose(zfinalevents[2], [zfinal])
+
+
+@pytest.mark.parametrize('method', ['RK23', 'RK45', 'DOP853', 'Radau', 'BDF', 'LSODA'])
+def test_integration_zero_rhs(method):
+    result = solve_ivp(fun_zero, [0, 10], np.ones(3), method=method)
+    assert_(result.success)
+    assert_equal(result.status, 0)
+    assert_allclose(result.y, 1.0, rtol=1e-15)
Repository: scipy/scipy

Issue:
DOC: Docstring in stats.anderson function not properly formatted
The docstring for the dist parameter ([code](https://github.com/scipy/scipy/blob/v1.5.0/scipy/stats/morestats.py#L1720-L1721)) in the anderson function is not formatted properly. Since there is a new line in the list of options for the parameter, the [documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.anderson.html#scipy-stats-anderson) does not show correclty.


Discussion:

Resolving patch:
diff --git a/scipy/stats/morestats.py b/scipy/stats/morestats.py
--- a/scipy/stats/morestats.py
+++ b/scipy/stats/morestats.py
@@ -1717,8 +1717,7 @@ def anderson(x, dist='norm'):
     ----------
     x : array_like
         Array of sample data.
-    dist : {'norm', 'expon', 'logistic', 'gumbel', 'gumbel_l', 'gumbel_r',
-        'extreme1'}, optional
+    dist : {'norm', 'expon', 'logistic', 'gumbel', 'gumbel_l', 'gumbel_r', 'extreme1'}, optional
         The type of distribution to test against.  The default is 'norm'.
         The names 'extreme1', 'gumbel_l' and 'gumbel' are synonyms for the
         same distribution.


Test patch:
Repository: scipy/scipy

Issue:
scipy.stats.dirichlet documentation issue
Hello.

The reference guide page at [`scipy.stats.dirichlet`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.dirichlet.html#scipy.stats.dirichlet) incorrectly states the support of the Dirichlet distribution as being the region $\sum_{I=1}^K x_i \le 1$.  In fact it should be the K-simplex $\sum_{I=1}^K x_i = 1$. The support is also bounded by the conditions $x_i\ge 1$, $i=1,\ldots,K$, which the documentation incorrectly omits.  Compare, for example, the description at [https://en.wikipedia.org/wiki/Dirichlet_distribution](url).

The examples that follow do in fact respect the K-simplex support, and the code throws an error (in the pdf method, for example), if the support condition is violated. It might be well to state this explicitly.

Regards,

Carlo Graziani


Discussion:

Resolving patch:
diff --git a/scipy/stats/_multivariate.py b/scipy/stats/_multivariate.py
--- a/scipy/stats/_multivariate.py
+++ b/scipy/stats/_multivariate.py
@@ -1356,8 +1356,11 @@ class dirichlet_gen(multi_rv_generic):
     support on the simplex defined by
 
     .. math::
-        \sum_{i=1}^{K} x_i \le 1
+        \sum_{i=1}^{K} x_i = 1
 
+    where 0 < x_i < 1.
+
+    If the quantiles don't lie within the simplex, a ValueError is raised.
 
     The probability density function for `dirichlet` is
 


Test patch:
Repository: scipy/scipy

Issue:
DOC: scipy.linalg.eigh
The docs say:

> lower bool, optional
>     Whether the pertinent array data is taken from the lower or upper triangle of a. (Default: lower)

but it is undocumented whether the same parameter **lower** is applied to b.



Discussion:

Resolving patch:
diff --git a/scipy/linalg/decomp.py b/scipy/linalg/decomp.py
--- a/scipy/linalg/decomp.py
+++ b/scipy/linalg/decomp.py
@@ -293,7 +293,7 @@ def eigh(a, b=None, lower=True, eigvals_only=False, overwrite_a=False,
         If omitted, identity matrix is assumed.
     lower : bool, optional
         Whether the pertinent array data is taken from the lower or upper
-        triangle of `a`. (Default: lower)
+        triangle of ``a`` and, if applicable, ``b``. (Default: lower)
     eigvals_only : bool, optional
         Whether to calculate only eigenvalues and no eigenvectors.
         (Default: both are calculated)
@@ -905,7 +905,7 @@ def eigvalsh(a, b=None, lower=True, overwrite_a=False,
         If omitted, identity matrix is assumed.
     lower : bool, optional
         Whether the pertinent array data is taken from the lower or upper
-        triangle of `a`. (Default: lower)
+        triangle of ``a`` and, if applicable, ``b``. (Default: lower)
     eigvals_only : bool, optional
         Whether to calculate only eigenvalues and no eigenvectors.
         (Default: both are calculated)
@@ -1006,9 +1006,9 @@ def eigvalsh(a, b=None, lower=True, overwrite_a=False,
     """
     return eigh(a, b=b, lower=lower, eigvals_only=True,
                 overwrite_a=overwrite_a, overwrite_b=overwrite_b,
-                turbo=turbo, eigvals=None, type=type,
-                check_finite=check_finite, subset_by_index=eigvals,
-                subset_by_value=None, driver=None)
+                turbo=turbo, eigvals=eigvals, type=type,
+                check_finite=check_finite, subset_by_index=subset_by_index,
+                subset_by_value=subset_by_value, driver=driver)
 
 
 def eigvals_banded(a_band, lower=False, overwrite_a_band=False,


Test patch:
diff --git a/scipy/linalg/tests/test_decomp.py b/scipy/linalg/tests/test_decomp.py
--- a/scipy/linalg/tests/test_decomp.py
+++ b/scipy/linalg/tests/test_decomp.py
@@ -881,6 +881,20 @@ def test_eigh(self, dim, dtype_, overwrite, lower, turbo, eigvals):
         diag2_ = diag(z.T.conj() @ b @ z).real
         assert_allclose(diag2_, ones(diag2_.shape[0]), rtol=0., atol=atol)
 
+    def test_eigvalsh_new_args(self):
+        a = _random_hermitian_matrix(5)
+        w = eigvalsh(a, eigvals=[1, 2])
+        assert_equal(len(w), 2)
+
+        w2 = eigvalsh(a, subset_by_index=[1, 2])
+        assert_equal(len(w2), 2)
+        assert_allclose(w, w2)
+
+        b = np.diag([1, 1.2, 1.3, 1.5, 2])
+        w3 = eigvalsh(b, subset_by_value=[1, 1.4])
+        assert_equal(len(w3), 2)
+        assert_allclose(w3, np.array([1.2, 1.3]))
+
 
 class TestLU(object):
     def setup_method(self):
Repository: scipy/scipy

Issue:
scipy.stats.poisson docs for rate = 0
I noticed that the docs for [scipy.stats.poisson](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html) are not clear about the intended behaviour when `\lambda = 0 `. 

Strictly speaking, the pmf for the Poisson is ill-defined at `\lambda = 0`; however, the `\lambda \to ` limit of a Poisson seems to me well-defined and intuitive,

    P(n | \lambda = 0) = { 1 if n = 0
                         { 0 otherwise
The mean and variance are `$E(n) = Var(n) = \lambda = 0$` as expected. The Poisson is implemented this way (requring only non-negative rate paramater) in [R](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Poisson.html), which should give some confidence that it isn't an obviously silly thing to do.

Indeed, the current behaviour appears to be just this,
```
>>> from scipy.stats import poisson
>>> poisson.pmf(1, 0.)
0.0
>>> poisson.pmf(0, 0.)
1.0
```

so, can we add a note to the docs that this is the intended treatment?

See https://github.com/scikit-hep/pyhf/issues/293#issuecomment-627207254 where this issue arose indirectly.



Discussion:

Resolving patch:
diff --git a/scipy/stats/_discrete_distns.py b/scipy/stats/_discrete_distns.py
--- a/scipy/stats/_discrete_distns.py
+++ b/scipy/stats/_discrete_distns.py
@@ -584,6 +584,8 @@ class poisson_gen(rv_discrete):
     for :math:`k \ge 0`.
 
     `poisson` takes :math:`\mu` as shape parameter.
+    When mu = 0 then at quantile k = 0, ``pmf`` method
+    returns `1.0`.
 
     %(after_notes)s
 


Test patch:
Repository: scipy/scipy

Issue:
unintuitive conversion in `scipy.constants.lambda2nu`
Instead of converting the input with `np.asanyarray`, the const float speed of light is converted.
It is working fine but it would be more intuitive when the argument gets converted (as it is done in `nu2lambda`).
However, it is questionable if these functions do serve any benefit.
Furthermore, their naming is not self-explaining.


Discussion:

Resolving patch:
diff --git a/scipy/constants/constants.py b/scipy/constants/constants.py
--- a/scipy/constants/constants.py
+++ b/scipy/constants/constants.py
@@ -273,7 +273,7 @@ def lambda2nu(lambda_):
     array([  2.99792458e+08,   1.00000000e+00])
 
     """
-    return _np.asanyarray(c) / lambda_
+    return c / _np.asanyarray(lambda_)
 
 
 def nu2lambda(nu):


Test patch:
diff --git a/scipy/constants/tests/test_constants.py b/scipy/constants/tests/test_constants.py
--- a/scipy/constants/tests/test_constants.py
+++ b/scipy/constants/tests/test_constants.py
@@ -27,9 +27,9 @@ def test_convert_temperature():
 
 
 def test_lambda_to_nu():
-    assert_equal(sc.lambda2nu(sc.speed_of_light), 1)
+    assert_equal(sc.lambda2nu([sc.speed_of_light, 1]), [1, sc.speed_of_light])
 
 
 def test_nu_to_lambda():
-    assert_equal(sc.nu2lambda(1), sc.speed_of_light)
+    assert_equal(sc.nu2lambda([sc.speed_of_light, 1]), [1, sc.speed_of_light])
Repository: scipy/scipy

Issue:
Create a 2-parameter version of the gamma distribution
The gamma distribution is [usually parameterized](https://en.wikipedia.org/wiki/Gamma_distribution) with two parameters, alpha and beta. The scipy implementation only implements `beta = 1`. It would be nice if we could implement different values of beta. Setting `scale = 1/beta` *almost* works, but is off by a factor of beta - see [calculation here](http://mathb.in/42774).

(Alternatively, if there is some way to recapture the 2-parameter version that I'm not seeing it would be good to put that in the documentation.) 





Discussion:
I'm not sure what you did. Missing a factor is not possible, because then the pdf wouldn't integrate to 1 to be a proper distribution.

The pdf needs to be multiplied by the scale when we do a scale transformation


Ah, I forgot that the scale parameter is applied twice: `gamma(x, scale) = gamma(x / scale) / scale`. This is where the missing factor comes in.

Would it be helpful if I submitted a PR updating the documentation to explain the relationship between scale and beta? I imagine others would have the same confusion I did.
@Xodarap a PR would be welcome indeed.

Resolving patch:
diff --git a/scipy/stats/_continuous_distns.py b/scipy/stats/_continuous_distns.py
--- a/scipy/stats/_continuous_distns.py
+++ b/scipy/stats/_continuous_distns.py
@@ -2547,7 +2547,7 @@ class gamma_gen(rv_continuous):
 
     .. math::
 
-        f(x, a) = \frac{x^{a-1} \exp(-x)}{\Gamma(a)}
+        f(x, a) = \frac{x^{a-1} e^{-x}}{\Gamma(a)}
 
     for :math:`x \ge 0`, :math:`a > 0`. Here :math:`\Gamma(a)` refers to the
     gamma function.
@@ -2556,7 +2556,17 @@ class gamma_gen(rv_continuous):
 
     When :math:`a` is an integer, `gamma` reduces to the Erlang
     distribution, and when :math:`a=1` to the exponential distribution.
+    
+    Gamma distributions are sometimes parameterized with two variables,
+    with a probability density function of:
 
+    .. math::
+
+        f(x, \alpha, \beta) = \frac{\beta^\alpha x^{\alpha - 1} e^{-\beta x }}{\Gamma(\alpha)}
+
+    Note that this parameterization is equivalent to the above, with 
+    ``scale = 1 / beta``.
+    
     %(after_notes)s
 
     %(example)s


Test patch: