Repository: scipy/scipy
File: scipy/stats/tests/test_marray.py (Python)

Code before:
@pytest.mark.parametrize('f', [make_xp_pytest_param(stats.pearsonr),
                               make_xp_pytest_param(stats.pointbiserialr)])
def test_pearsonr(f, xp):
    mxp, marrays, narrays = get_arrays(2, shape=(25,), xp=xp)
    res = f(*marrays)

    x, y = narrays
    mask = np.isnan(x) | np.isnan(y)
    ref = f(x[~mask], y[~mask])

    xp_assert_close(res.statistic.data, xp.asarray(ref.statistic))
    xp_assert_close(res.pvalue.data, xp.asarray(ref.pvalue))

    if f == stats.pearsonr:
        res_ci_low, res_ci_high = res.confidence_interval()
        ref_ci_low, ref_ci_high = ref.confidence_interval()
        xp_assert_close(res_ci_low.data, xp.asarray(ref_ci_low))
        xp_assert_close(res_ci_high.data, xp.asarray(ref_ci_high))


@skip_backend('dask.array', reason='Arrays need `device` attribute: dask/dask#11711')
@skip_backend('jax.numpy', reason="JAX doesn't allow item assignment.")
@skip_backend('torch', reason="array-api-compat#242")
@skip_backend('cupy', reason="special functions won't work")
@pytest.mark.parametrize('f', [make_xp_pytest_param(stats.linregress),
                               ])
def test_linregress(f, xp):
    mxp, marrays, narrays = get_arrays(2, shape=(25,), xp=xp)
    res = f(*marrays)

    x, y = narrays
    mask = np.isnan(x) | np.isnan(y)
    ref = f(x[~mask], y[~mask])

    xp_assert_close(res.slope.data, xp.asarray(ref.slope))
    xp_assert_close(res.intercept.data, xp.asarray(ref.intercept))
    xp_assert_close(res.rvalue.data, xp.asarray(ref.rvalue))
    xp_assert_close(res.pvalue.data, xp.asarray(ref.pvalue))
    xp_assert_close(res.stderr.data, xp.asarray(ref.stderr))
    xp_assert_close(res.intercept_stderr.data, xp.asarray(ref.intercept_stderr))


@make_xp_test_case(stats.entropy)
@skip_backend('dask.array', reason='Arrays need `device` attribute: dask/dask#11711')
@skip_backend('jax.numpy', reason="JAX doesn't allow item assignment.")
@pytest.mark.parametrize('qk', [False, True])
@pytest.mark.parametrize('axis', [0, 1, None])
def test_entropy(qk, axis, xp):
    mxp, marrays, narrays = get_arrays(2 if qk else 1, xp=xp)
    res = stats.entropy(*marrays, axis=axis)
    ref = stats.entropy(*narrays, nan_policy='omit', axis=axis)

Review comment (suggestion):
```suggestion
@pytest.mark.parametrize('f', [make_xp_pytest_param(stats.linregress)])
```

Code after:
@pytest.mark.parametrize('f', [make_xp_pytest_param(stats.pearsonr),
                               make_xp_pytest_param(stats.pointbiserialr)])
def test_pearsonr(f, xp):
    mxp, marrays, narrays = get_arrays(2, shape=(25,), xp=xp)
    res = f(*marrays)

    x, y = narrays
    mask = np.isnan(x) | np.isnan(y)
    ref = f(x[~mask], y[~mask])

    xp_assert_close(res.statistic.data, xp.asarray(ref.statistic))
    xp_assert_close(res.pvalue.data, xp.asarray(ref.pvalue))

    if f == stats.pearsonr:
        res_ci_low, res_ci_high = res.confidence_interval()
        ref_ci_low, ref_ci_high = ref.confidence_interval()
        xp_assert_close(res_ci_low.data, xp.asarray(ref_ci_low))
        xp_assert_close(res_ci_high.data, xp.asarray(ref_ci_high))


@skip_backend('dask.array', reason='Arrays need `device` attribute: dask/dask#11711')
@skip_backend('jax.numpy', reason="JAX doesn't allow item assignment.")
@skip_backend('torch', reason="array-api-compat#242")
@skip_backend('cupy', reason="special functions won't work")
@pytest.mark.parametrize('f', [make_xp_pytest_param(stats.linregress)])
def test_linregress(f, xp):
    mxp, marrays, narrays = get_arrays(2, shape=(25,), xp=xp)
    res = f(*marrays)

    x, y = narrays
    mask = np.isnan(x) | np.isnan(y)
    ref = f(x[~mask], y[~mask])

    xp_assert_close(res.slope.data, xp.asarray(ref.slope))
    xp_assert_close(res.intercept.data, xp.asarray(ref.intercept))
    xp_assert_close(res.rvalue.data, xp.asarray(ref.rvalue))
    xp_assert_close(res.pvalue.data, xp.asarray(ref.pvalue))
    xp_assert_close(res.stderr.data, xp.asarray(ref.stderr))
    xp_assert_close(res.intercept_stderr.data, xp.asarray(ref.intercept_stderr))


@make_xp_test_case(stats.entropy)
@skip_backend('dask.array', reason='Arrays need `device` attribute: dask/dask#11711')
@skip_backend('jax.numpy', reason="JAX doesn't allow item assignment.")
@pytest.mark.parametrize('qk', [False, True])
@pytest.mark.parametrize('axis', [0, 1, None])
def test_entropy(qk, axis, xp):
    mxp, marrays, narrays = get_arrays(2 if qk else 1, xp=xp)
    res = stats.entropy(*marrays, axis=axis)
    ref = stats.entropy(*narrays, nan_policy='omit', axis=axis)
    xp_assert_close(res.data, xp.asarray(ref))