Skip to content

Groupby count doesn't accept sort= keyword #28755

Closed
@mrocklin

Description

@mrocklin

Many groupby aggregations like sum, min, max, mean, and so on take a sort= keyword. Count doesn't for some reason.

In [1]: import pandas as pd

In [2]: df = pd.DataFrame({"x": [3, 4, 1, 3, 4, 1], "y": [1, 2, 3, 4, 5, 6]})

In [3]: df.groupby("x").y.sum(sort=False)
Out[3]:
x
1    9
3    5
4    7
Name: y, dtype: int64

In [4]: df.groupby("x").y.count(sort=False)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-76e5507e57cb> in <module>
----> 1 df.groupby("x").y.count(sort=False)

TypeError: count() got an unexpected keyword argument 'sort'

Is this intentional? Is it a bug? I was trying to turn off sorting intermediate results in dask dataframe by default to speed things up a bit (it's also for cudf/RAPIDS work) and ran into this. The inconsistency makes things slightly inconvenient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions