Skip to content

SeriesGroupBy.value_counts() should return Series not DataFrame #442

Closed
@Dr-Irv

Description

@Dr-Irv

Describe the bug
From discussion here: #203 (comment)

To Reproduce

import pandas as pd

df = pd.DataFrame(
    {
        "Animal": ["Falcon", "Falcon", "Parrot", "Parrot"],
        "Max Speed": [380, 370, 24, 26],
    }
)
c: pd.Series = df.groupby("Animal")["Max Speed"].value_counts()
print(type(c))  # <class 'pandas.core.series.Series'>
print(c.index)
print(c)

mypy and pyright report that there is a mismatch in the result.

In pandas source, SeriesGroupBy.value_counts() always returns Series . Need to make that change in typing stubs.

But should copy overloads from DataFrameGroupBy for value_counts() to handle normalize argument correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffGroupbygood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions