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
DEP: add deprecation warning for binom_test #16307
Conversation
Hey @h-vetinari, could you please take a look at this PR? |
I see the following error in the build. Is it something simple? Do I need something like this to silence this?
|
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.
Thanks @deadb0d4 for the PR. I have a suggestion.
The CI failures are unrelated and was fixed on main recently. Can you merge main to your branch please?
I only get this error
And with
|
You probably have some caching here. |
Weird HTTP error on check...
|
It's fine. Not linked to this PR and intermittent on main. |
@deadb0d4 @h-vetinari since it was previously asked to only doc-deprecate, could you send an email to the mailing list before we get this in? |
I've sent an email to scipy-dev@python.org. Since I am the first time contributor and new subscriber, I believe it needs a verification. |
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.
I think we should switch most of the tests to binomtest
directly
scipy/stats/tests/test_stats.py
Outdated
with np.testing.suppress_warnings() as sup: | ||
sup.filter(DeprecationWarning, "'binom_test' is deprecated") | ||
for p, res in zip(pp, results): | ||
assert_approx_equal(stats.binom_test(x, n, p), res, | ||
significant=12, err_msg='fail forp=%f' % p) | ||
assert_approx_equal(stats.binom_test(50, 100, 0.1), | ||
5.8320387857343647e-024, | ||
significant=12) |
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.
Instead of adding a deprecation warning, can you please just switch to using binomtest
here?
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.
Hey @h-vetinari, with your comment below, do I get you correctly that we should only check binom_test
in the below and switch to binomtest
everywhere else?
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.
Yes. Let's use the non-deprecated everywhere, except where we're testing the deprecation (and equivalence with the new method) explicitly.
scipy/stats/tests/test_stats.py
Outdated
def test_binom_test_deprecation(): | ||
deprecation_msg = ("'binom_test' is deprecated in favour of" | ||
" 'binomtest' and will be removed in Scipy 1.11.0.") | ||
with pytest.warns(DeprecationWarning, match=deprecation_msg): | ||
stats.binom_test([1, 1]) |
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.
In fact, this is essentially the only test we need for the deprecated binom_test
, though I think we should extend it to also check equality with the result of binomtest
. Something like:
@pytest.mark.parametrize('alternative', ['two-sided', 'greater', 'less'])
def test_binom_test_deprecation(alternative):
num = 10
X = np.random.randint(10, 100, (num,))
# needs N >= X
N = X + np.random.randint(0, 100, (num,))
P = np.random.uniform(0, 1, (num,))
deprecation_msg = ("'binom_test' is deprecated in favour of"
" 'binomtest' and will be removed in Scipy 1.11.0.")
for x, n, p in zip(X, N, P):
with pytest.warns(DeprecationWarning, match=deprecation_msg):
res = stats.binom_test(x, n, p, alternative=alternative)
assert res = stats.binomtest(x, n, p, alternative=alternative)
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.
A heads up. The branching to 1.9 was done yesterday. So unless there is a compelling reason to make the work to backport this to the maintenance branch, we might have to update the deprecation version to 1.12.
scipy/stats/_morestats.py
Outdated
@@ -2645,6 +2646,8 @@ def levene(*samples, center='median', proportiontocut=0.05): | |||
return LeveneResult(W, pval) | |||
|
|||
|
|||
@_deprecated("'binom_test' is deprecated in favour of" | |||
" 'binomtest' and will be removed in Scipy 1.11.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.
Personally when reading deprecation message, the critical information is since when the alternative is present – not when the current one will be removed. From my understanding this means binomtest
is available since 0.19.0, so I would state that in the deprecation message as well.
Knowing since when it is available is often the difference between understanding whether you can do a blind rename, of have to do conditional based on version number.
Just my 2c.
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.
@Carreau does the new message look good to you?
Add a missing whitespace Co-authored-by: Pamphile Roy <roy.pamphile@gmail.com>
Updated tests & warning message. Could you please take a look? |
Co-authored-by: Pamphile Roy <roy.pamphile@gmail.com>
Co-authored-by: Pamphile Roy <roy.pamphile@gmail.com>
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.
LGTM, let's wait an extra week to give time for people since you sent something to the mailing list.
Hey @tupui, Can we merge this PR now? |
Yes it's been a week now. Thank you again @deadb0d4 for the PR and everyone else for the reviews 😃 |
Reference issue
Closes #16256.
What does this implement/fix?
stats.binom_test
was deprecated in documentation only. This PR adds a deprecation warning and test.Additional information