-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: SeriesGroupBy.apply sets name attribute if result is DataFrame #49908
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
56a7a19
to
84ee37e
Compare
a1b2edf
to
c863f89
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.
Looking good!
@@ -401,7 +401,8 @@ def _wrap_applied_output( | |||
not_indexed_same=not_indexed_same, | |||
is_transform=is_transform, | |||
) | |||
result.name = self.obj.name | |||
if isinstance(result, 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.
Can you use result.ndim == 1
here instead.
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.
sure, will do - though just for my understanding, why?
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.
Interesting - it used to be that isinstance checks were quite a bit more expensive than checking the ndim
attribute; I'm now seeing isinstance is slightly cheaper. With type checkers able to naturally derive type information from isinstance checks in code paths, we should certainly prefer isinstance if they are just as performant.
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.
@MarcoGorelli - I'm good with either using ndim or isinstance here; I plan on taking a more in depth look of our usage. Let me know what you think.
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.
no preference from my end
@MarcoGorelli I added back the Bug tag. I've been doing that on regressions to differ between e.g. a performance regression and a behavior regression. Let me know if you think differently. |
Hey - sounds good to me |
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 @MarcoGorelli! |
…ibute if result is DataFrame
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.