Skip to content

Commit e1aeb21

Browse files
authored
Merge pull request scipy#22844 from crusaderky/stats_tst_nits
TST: `stats`: minor nits to test_stats.py
2 parents e29a7a8 + a511507 commit e1aeb21

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

scipy/stats/tests/test_stats.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from scipy._lib.array_api_extra.testing import lazy_xp_function
4949

5050
skip_xp_backends = pytest.mark.skip_xp_backends
51-
boolean_index_skip_reason = 'JAX/Dask arrays do not support boolean assignment.'
5251

5352

5453
""" Numbers in docstrings beginning with 'W' refer to the section numbers
@@ -554,7 +553,7 @@ def test_length_two_constant_input(self, xp):
554553
# cor.test(x, y, method = "pearson", alternative = "g")
555554
# correlation coefficient and p-value for alternative='two-sided'
556555
# calculated with mpmath agree to 16 digits.
557-
@pytest.mark.skip_xp_backends(np_only=True)
556+
@skip_xp_backends(np_only=True)
558557
@pytest.mark.parametrize('alternative, pval, rlow, rhigh, sign',
559558
[('two-sided', 0.325800137536, -0.814938968841, 0.99230697523, 1),
560559
('less', 0.8370999312316, -1, 0.985600937290653, 1),
@@ -4016,7 +4015,7 @@ def test_1samp_alternative(self, xp):
40164015
xp_assert_close(p, xp.asarray(self.P1_1_g))
40174016
xp_assert_close(t, xp.asarray(self.T1_1))
40184017

4019-
@pytest.mark.skip_xp_backends('jax.numpy', reason='Generic stdtrit mutates array.')
4018+
@skip_xp_backends('jax.numpy', reason='Generic stdtrit mutates array.')
40204019
@pytest.mark.parametrize("alternative", ['two-sided', 'less', 'greater'])
40214020
def test_1samp_ci_1d(self, xp, alternative):
40224021
# test confidence interval method against reference values
@@ -4049,7 +4048,7 @@ def test_1samp_ci_iv(self, xp):
40494048
with pytest.raises(ValueError, match=message):
40504049
res.confidence_interval(confidence_level=10)
40514050

4052-
@pytest.mark.skip_xp_backends(np_only=True, reason='Too slow.')
4051+
@skip_xp_backends(np_only=True, reason='Too slow.')
40534052
@pytest.mark.xslow
40544053
@hypothesis.given(alpha=hypothesis.strategies.floats(1e-15, 1-1e-15),
40554054
data_axis=ttest_data_axis_strategy())
@@ -5676,8 +5675,7 @@ def test_resampling_input_validation(self):
56765675
with pytest.raises(ValueError, match=message):
56775676
stats.ttest_ind([1, 2, 3], [4, 5, 6], method='migratory')
56785677

5679-
@pytest.mark.skip_xp_backends(cpu_only=True,
5680-
reason='Uses NumPy for pvalue, CI')
5678+
@skip_xp_backends(cpu_only=True, reason='Uses NumPy for pvalue, CI')
56815679
def test_permutation_not_implement_for_xp(self, xp):
56825680
a2, b2 = xp.asarray(self.a2), xp.asarray(self.b2)
56835681

@@ -5904,8 +5902,7 @@ def test_errors_unsupported(self):
59045902
stats.ttest_ind([1, 2], [2, 3], trim=.2, permutations=2,
59055903
random_state=2)
59065904

5907-
@pytest.mark.skip_xp_backends(cpu_only=True,
5908-
reason='Uses NumPy for pvalue, CI')
5905+
@skip_xp_backends(cpu_only=True, reason='Uses NumPy for pvalue, CI')
59095906
def test_permutation_not_implement_for_xp(self, xp):
59105907
message = "Use of `trim` is compatible only with NumPy arrays."
59115908
a, b = xp.arange(10), xp.arange(10)+1
@@ -5969,7 +5966,7 @@ class Test_ttest_CI:
59695966
@pytest.mark.parametrize('alternative', ['two-sided', 'less', 'greater'])
59705967
@pytest.mark.parametrize('equal_var', [False, True])
59715968
@pytest.mark.parametrize('trim', [0, 0.2])
5972-
@pytest.mark.skip_xp_backends('jax.numpy', reason='Generic stdtrit mutates array.')
5969+
@skip_xp_backends('jax.numpy', reason='Generic stdtrit mutates array.')
59735970
def test_confidence_interval(self, alternative, equal_var, trim, xp):
59745971
if equal_var and trim:
59755972
pytest.xfail('Discrepancy in `main`; needs further investigation.')
@@ -6282,6 +6279,7 @@ def _convert_pvalue_alternative(t, p, alt, xp):
62826279
@pytest.mark.slow
62836280
@pytest.mark.filterwarnings("ignore:divide by zero encountered:RuntimeWarning:dask")
62846281
@pytest.mark.filterwarnings("ignore:invalid value encountered:RuntimeWarning:dask")
6282+
@make_skip_xp_backends(stats.ttest_1samp)
62856283
def test_ttest_1samp_new(xp):
62866284
n1, n2, n3 = (10, 15, 20)
62876285
rvn1 = stats.norm.rvs(loc=5, scale=10, size=(n1, n2, n3))
@@ -6342,8 +6340,7 @@ def test_ttest_1samp_new(xp):
63426340
xp_assert_equal(res.pvalue, xp.asarray([1., xp.nan]))
63436341

63446342

6345-
@pytest.mark.skip_xp_backends(np_only=True,
6346-
reason="Only NumPy has nan_policy='omit' for now")
6343+
@skip_xp_backends(np_only=True, reason="Only NumPy has nan_policy='omit' for now")
63476344
def test_ttest_1samp_new_omit(xp):
63486345
n1, n2, n3 = (5, 10, 15)
63496346
rvn1 = stats.norm.rvs(loc=5, scale=10, size=(n1, n2, n3))
@@ -7027,7 +7024,7 @@ def test_2d_axis1_with_zero(self, xp):
70277024
desired = np.array([0.0, 63.03939962, 103.80078637])
70287025
check_equal_hmean(a, desired, axis=1, xp=xp)
70297026

7030-
@pytest.mark.skip_xp_backends(
7027+
@skip_xp_backends(
70317028
np_only=True,
70327029
reason='array-likes only supported for NumPy backend',
70337030
)
@@ -7156,7 +7153,7 @@ def test_1d_neg(self, xp):
71567153
with np.errstate(invalid='ignore'):
71577154
check_equal_gmean(a, desired, xp=xp)
71587155

7159-
@pytest.mark.skip_xp_backends(
7156+
@skip_xp_backends(
71607157
np_only=True,
71617158
reason='array-likes only supported for NumPy backend',
71627159
)
@@ -7272,7 +7269,7 @@ def test_weights_1d(self, xp):
72727269
desired = TestPMean.wpmean_reference(np.array(a), p, weights)
72737270
check_equal_pmean(a, p, desired, weights=weights, rtol=1e-5, xp=xp)
72747271

7275-
@pytest.mark.skip_xp_backends(
7272+
@skip_xp_backends(
72767273
np_only=True,
72777274
reason='array-likes only supported for NumPy backend',
72787275
)
@@ -9744,8 +9741,7 @@ def test_chk_asarray(xp):
97449741
assert_equal(axis_out, axis)
97459742

97469743

9747-
@pytest.mark.skip_xp_backends('numpy',
9748-
reason='These parameters *are* compatible with NumPy')
9744+
@skip_xp_backends('numpy', reason='These parameters *are* compatible with NumPy')
97499745
def test_axis_nan_policy_keepdims_nanpolicy(xp):
97509746
# this test does not need to be repeated for every function
97519747
# using the _axis_nan_policy decorator. The test is here

0 commit comments

Comments
 (0)