Skip to content

DOC: DataFrame.count_values supports single label #50829

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

Closed
1 task done
mattf opened this issue Jan 18, 2023 · 2 comments · Fixed by #50955
Closed
1 task done

DOC: DataFrame.count_values supports single label #50829

mattf opened this issue Jan 18, 2023 · 2 comments · Fixed by #50955
Assignees
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Docs good first issue Testing pandas testing functions or related to the test suite
Milestone

Comments

@mattf
Copy link

mattf commented Jan 18, 2023

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.value_counts.html

Documentation problem

documentation claims the subset must be list-like, optional

the implementation uses DataFrame.groupby, which accepts mapping, function, label, or list of labels

the result is value_counts can accept a single label

In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '1.5.2'

In [3]: df = pd.DataFrame({"XYZ": ["foo", "foo", "foo", "foo", "foo"]})

In [4]: df.value_counts("XYZ")
Out[4]: 
XYZ
foo    5
dtype: int64

Suggested fix for documentation

  1. change the value_counts documentation to reflect its capabilities
  2. change the value_counts implementation to reflect the documentation

use of groupby goes to value_count's inception, and groupby's api has been consistent since 1.0

+1 option (1)

@mattf mattf added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 18, 2023
@mroeschke
Copy link
Member

Thanks for the report. Additionally I don't see any testing of a single label subset so that would be good to add as well.

@mroeschke mroeschke added Testing pandas testing functions or related to the test suite Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff good first issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 18, 2023
@tpackard1
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Docs good first issue Testing pandas testing functions or related to the test suite
Projects
None yet
4 participants