Skip to content

Conversation

mdhaber
Copy link
Contributor

@mdhaber mdhaber commented Apr 13, 2023

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.

@mdhaber mdhaber added scipy.stats maintenance Items related to regular maintenance tasks labels Apr 13, 2023
@@ -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. "
Copy link
Contributor Author

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).

Copy link
Member

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?

Copy link
Contributor Author

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.

@j-bowhay
Copy link
Member

j-bowhay commented Apr 13, 2023

I think there are some more place to be cleaned up in test_stats.py:

if dtype == 'object':
with pytest.warns(DeprecationWarning, match=self.deprecation_msg):
res = stats.mode(a, axis=axis, keepdims=False)
else:
res = stats.mode(a, axis=axis, keepdims=False)

deprecation_msg = r"Support for non-numeric arrays has been deprecated"

@mdhaber mdhaber closed this Apr 13, 2023
@mdhaber mdhaber reopened this Apr 14, 2023
@j-bowhay j-bowhay added the deprecated Items related to behavior that has been deprecated label Apr 14, 2023
@j-bowhay j-bowhay added this to the 1.11.0 milestone Apr 14, 2023
@j-bowhay j-bowhay merged commit 30be781 into scipy:main Apr 14, 2023
@h-vetinari h-vetinari mentioned this pull request May 20, 2023
32 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated Items related to behavior that has been deprecated maintenance Items related to regular maintenance tasks scipy.stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants