-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Fix GroupBy.idxmin/idxmax retrun wrong type on empty #51423
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 GroupBy.idxmin/idxmax retrun wrong type on empty #51423
Conversation
pandas/core/groupby/generic.py
Outdated
func.__name__ = "idxmax" | ||
return self._idxmin_idxmax(func) | ||
|
||
def _idxmin_idxmax(self, func: Callable) -> DataFrame | Series: |
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.
what if instead of all this you just did return result.astype(self.obj.index.dtype, copy=False)
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.
It seems that there are some problems with implementing it directly like this.
If it's better to make minimal changes to the code on the existing basis in this way, I will go ahead and fix these problem on this basis..
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 can't dtype
directly to all result
, because there are some types can't be converted to each other, such as inf
and NA
.
Therefore, I tried to convert only the empty result. Based on the original code, the type is incorrect only when the return value is empty.
@jbrockmendel any suggestion?
7854611
to
ae26c2e
Compare
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
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
Thanks @luke396 |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.