Skip to content

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

Closed
@rhshadrach

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapBugGroupby

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions