Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: stats.ttest_1samp: fix xslow test #20642

Merged
merged 2 commits into from
May 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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