-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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: Fix passing of numeric_only argument for categorical reduce #25304
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why are u adding a code path here? the original is much more generic ; need to avoid special cases like this
if u need to handle this specially then the place is in the Categirical itself
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.
This is because Categorical deviates here from the standard ExtensionArray (see #25303 for the issue about that).
I personally find it clearer with this special case, making it explicit that Categorical has a different signature. And after the deprecation period, we can remove this special case.
If you feel strongly about it, it can indeed be handled inside Categorical. But that means that all the other arrays'
_reduce
method needs to be updated as well to handle (=ignore)numeric_only
, which is also not clean (and the special case here is only temporarily anyway).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.
this is not more clear and leads to future issues
pls move to _reduce
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.
not sure why the others need to change at all you’re logic is circular
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.
This would cause more changes, since the problem is actually that the argument
numeric_only
is not passed currently. If we would add it for everyExtensionArray
call we get problems at the other reduction methods. For instance here: https://github.com/pandas-dev/pandas/blob/master/pandas/core/arrays/numpy_.py#L322 (they don't havenumeric_only
, or**kwargs
in the method definition).So we could change the call for every
ExtenensionArray
to:return delegate._reduce(name, skipna=skipna, numeric_only=numeric_only, **kwds)
but then we would need to make sure every child of ExtensionArray supports this and this is currently not the case.
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.
@arnov explained it well. I think we don't want to change the EA interface (
_reduce
is an official part of it) just for this back-compat special case we are going to deprecate. Hence, categorical needs to be handled separately here (but again, this is only temporary)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.
disagree numeric_only is likely not going away anytime soon and even so
the EA simply need to accept it (they can ignore it)
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.
@jreback this is not about the numeric_only in DataFrame/Series reductions that determines for which columns the reduction is calculated. This is another meaning of the keyword only for categorical that determines whether NaNs should be skipped or not. Please read #25303
So we are not speaking about removing that general use case of
numeric_only
, but only the one in Categorical.min/max.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’ll look closer but am still -1 on any handling as a special case in the Series call
the point is that pass on kwargs; EA can ignore or not as required
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.
OK, to take a step back: @jreback do you agree that in the long term we can deprecate this
numeric_only
keyword for Categorical.min/max?(it's the only EA that now uses it, while the others all use
skipna
for the same thing)