Skip to content
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

SeriesGroupBy.apply results in wrong name when there is a single group #46369

Closed
rhshadrach opened this issue Mar 15, 2022 · 0 comments · Fixed by #46623
Closed

SeriesGroupBy.apply results in wrong name when there is a single group #46369

rhshadrach opened this issue Mar 15, 2022 · 0 comments · Fixed by #46623
Labels
Apply Apply, Aggregate, Transform Bug Groupby
Milestone

Comments

@rhshadrach
Copy link
Member

rhshadrach commented Mar 15, 2022

df = pd.DataFrame({'a': [0], 'b': [1]})
ser = df['b'].rename(None)
print(ser.groupby(df['a']).apply(lambda x: x))

df = pd.DataFrame({'a': [0, 1], 'b': [1, 2]})
ser = df['b'].rename(None)
print(ser.groupby(df['a']).apply(lambda x: x))

produces

0    1
Name: 0, dtype: int64
0    1
1    2
dtype: int64

In the first case, the name attribute on the resulting Series is set as 0, the group. In the second case, the two groups have different names and so the correct name attribute of None is on the result. The name attribute should be None in the first case as well.

@rhshadrach rhshadrach added Bug Groupby Apply Apply, Aggregate, Transform labels Mar 15, 2022
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Mar 15, 2022
@rhshadrach rhshadrach changed the title SeriesGroupBy.apply results in wrong name when there is a single grouper SeriesGroupBy.apply results in wrong name when there is a single group Mar 18, 2022
@jreback jreback modified the milestones: Contributions Welcome, 1.5 Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform Bug Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants