Skip to content

Commit

Permalink
Merge pull request #20642 from mdhaber/gh20641
Browse files Browse the repository at this point in the history
TST: stats.ttest_1samp: fix xslow test
  • Loading branch information
tylerjereddy committed May 5, 2024
2 parents 9ee34f9 + 43db12f commit 7f0a5cb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scipy/stats/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3559,10 +3559,12 @@ def test_kurtosis_constant_value(self):
@hypothesis.strategies.composite
def ttest_data_axis_strategy(draw):
# draw an array under shape and value constraints
dtype = npst.floating_dtypes()
elements = dict(allow_nan=False, allow_infinity=False)
shape = npst.array_shapes(min_dims=1, min_side=2)
data = draw(npst.arrays(dtype=dtype, elements=elements, shape=shape))
# The test that uses this, `test_pvalue_ci`, uses `float64` to test
# extreme `alpha`. It could be adjusted to test a dtype-dependent
# range of `alpha` if this strategy is needed to generate other floats.
data = draw(npst.arrays(dtype=np.float64, elements=elements, shape=shape))

# determine axes over which nonzero variance can be computed accurately
ok_axes = []
Expand Down Expand Up @@ -3711,7 +3713,6 @@ def test_1samp_ci_iv(self, xp):
def test_pvalue_ci(self, alpha, data_axis, alternative, xp):
# test relationship between one-sided p-values and confidence intervals
data, axis = data_axis
data = data.astype(copy=True) # ensure byte order
data = xp.asarray(data)
res = stats.ttest_1samp(data, 0.,
alternative=alternative, axis=axis)
Expand All @@ -3722,7 +3723,8 @@ def test_pvalue_ci(self, alpha, data_axis, alternative, xp):
res = stats.ttest_1samp(data, popmean, alternative=alternative, axis=axis)
shape = list(data.shape)
shape.pop(axis)
ref = xp.broadcast_to(xp.asarray(1-alpha), shape)
# `float64` is used to correspond with extreme range of `alpha`
ref = xp.broadcast_to(xp.asarray(1-alpha, dtype=xp.float64), shape)
xp_assert_close(res.pvalue, ref)


Expand Down

0 comments on commit 7f0a5cb

Please sign in to comment.