Skip to content

BUG: Wrong error message is raised when columns=None in df.pivot #30924

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
charlesdong1991 opened this issue Jan 11, 2020 · 2 comments · Fixed by #30925
Closed

BUG: Wrong error message is raised when columns=None in df.pivot #30924

charlesdong1991 opened this issue Jan 11, 2020 · 2 comments · Fixed by #30925
Labels
Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@charlesdong1991
Copy link
Member

charlesdong1991 commented Jan 11, 2020

From docstring, index and values can be optional in df.pivot, but columns is not

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.pivot.html

index : string or object, optional
Column to use to make new frame’s index. If None, uses existing index.

columns : string or object
Column to use to make new frame’s columns.

However, the error message is confusing now, should raise columns is not optional.

Code example:

>>> df = pd.DataFrame({"foo": ['one', 'one', 'two', 'two'],"bar": ['A', 'A', 'B', 'C'],"baz": [1, 2, 3, 4]})
>>> df.pivot(columns=None)

KeyError: 'None of [None] are in the columns'
@charlesdong1991 charlesdong1991 changed the title BUG: No error is raised when columns=None in df.pivot BUG: Wrong error message is raised when columns=None in df.pivot Jan 11, 2020
@charlesdong1991 charlesdong1991 added the Error Reporting Incorrect or improved errors from pandas label Jan 11, 2020
@simonjayhawkins
Copy link
Member

@charlesdong1991 Thanks for the report. can you show a code sample and the error message raised for completeness.

@simonjayhawkins simonjayhawkins added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Jan 13, 2020
@charlesdong1991
Copy link
Member Author

sure, updated in the issue description @simonjayhawkins

@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants