-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
DEP: stats.mode: raise with non-numeric input #18290
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
Conversation
@@ -501,6 +501,12 @@ def mode(a, axis=0, nan_policy='propagate', keepdims=False): | |||
|
|||
""" # noqa: E501 | |||
# `axis`, `nan_policy`, and `keepdims` are handled by `_axis_nan_policy` | |||
if not np.issubdtype(a.dtype, np.number): | |||
message = ("Argument `a` is not recognized as numeric. " |
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.
Phrased like this to reduce confusion when the input appears to be numeric but isn't coerced to numeric type (e.g. Series
with pandas integers).
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.
are you intending to drop bool
on purpose 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.
Yes, for now. The deprecation warning was produced under the same conditions as the error message would be with this PR, so it should be OK.
I think there are some more place to be cleaned up in scipy/scipy/stats/tests/test_stats.py Lines 2295 to 2299 in c62be9c
scipy/scipy/stats/tests/test_stats.py Line 2212 in c62be9c
|
Reference issue
#18254 (comment)
What does this implement/fix?
One resolution of gh-18245 was that
stats.mode
should raise when input is non-numeric. This implements that.