Skip to content

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

Merged
merged 4 commits into from
Nov 27, 2022

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli added Bug Groupby Apply Apply, Aggregate, Transform, Map labels Nov 25, 2022
@MarcoGorelli MarcoGorelli force-pushed the grp-apply-sets-name branch 2 times, most recently from a1b2edf to c863f89 Compare November 25, 2022 15:00
@MarcoGorelli MarcoGorelli added Regression Functionality that used to work in a prior pandas version and removed Bug labels Nov 25, 2022
Copy link
Member

@rhshadrach rhshadrach left a 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):
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

@rhshadrach rhshadrach Nov 25, 2022

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.

Copy link
Member

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.

Copy link
Member Author

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

@rhshadrach rhshadrach added this to the 1.5.3 milestone Nov 27, 2022
@rhshadrach rhshadrach added the Bug label Nov 27, 2022
@rhshadrach
Copy link
Member

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

@MarcoGorelli
Copy link
Member Author

@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

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rhshadrach rhshadrach merged commit 15e6abd into pandas-dev:main Nov 27, 2022
@rhshadrach
Copy link
Member

Thanks @MarcoGorelli!

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Nov 27, 2022
MarcoGorelli added a commit that referenced this pull request Nov 27, 2022
…me attribute if result is DataFrame) (#49928)

Backport PR #49908:  BUG: SeriesGroupBy.apply sets name attribute if result is DataFrame

Co-authored-by: Marco Edward Gorelli <33491632+MarcoGorelli@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby Regression Functionality that used to work in a prior pandas version
2 participants