-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
BUG: stats.ttest_1samp: fix use of keepdims
#20734
Conversation
Also set the `too_small` argument of `ttest_1samp`'s decorator to a callable that checks if the `a` argument has at least 1 sample. Otherwise, we get a division-by-zero warning.
@mdhaber Ok so it seems most errors that occur when running |
In that case, maybe leave the existing test alone if it's that strict. Instead, add a new test like it that doesn't generate such cases, since they seem orthogonal to the issue of non-expandable scalars. The inconsistent behavior w.r.t. small samples is being fixed separately; when that's resolved, we can probably combine the tests more easily. |
keepdims
for scipy.stats.ttest_1samp
keepdims
This fixes a bug as-is, so I'd like this to make it into 1.14.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If tests pass, I'll merge.
@tylerjereddy can we backport this fix into the next release candidate?
Reference issue
Partially addresses gh-20725.
What does this implement/fix?
This PR fixes an error raised when using the
keepdims
argument ofscipy.stats.ttest_1samp
. The error comes from the_axis_nan_policy_factory
decorator that tries to expand the dimensions of all returns from decorator functions. Some of the decorated functions return simple integers that cannot be expanded, thus the error:scipy/scipy/stats/_axis_nan_policy.py
Lines 240 to 246 in 626bbd1
Additional information
test_keepdims
originally raised an error when addingstats.ttest_1samp
due to a division-by-zero warning. The error is due to some test cases where omitting NaNs leads to samples of size 1, thus the division-by-zero when computing the SEM. To fix this, I set thetoo_small
argument to a callable that checks if the sample to test has at least size 2. I could not simply usetoo_small=1
however, since it seemspopmean
is considered a sample (ie.,n_samples
is set to 2 in the decorator ofttest_1samp
).Adding all other functions from
axis_nan_policy_cases
raises many more errors that I'll try to check now.