Skip to content

DOC: DataFrame.query() are contradictory on whether Python keywords can used as identifiers #35989

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
jpeacock29 opened this issue Aug 30, 2020 · 2 comments · Fixed by #36311
Closed
Milestone

Comments

@jpeacock29
Copy link
Contributor

jpeacock29 commented Aug 30, 2020

Location of the documentation

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

Documentation problem

The expr parameter is described as follows:

You can refer to column names that contain spaces or operators by surrounding them in backticks. This way you can also escape names that start with a digit, or those that are a Python keyword. Basically when it is not valid Python identifier. See notes down for more details.

However, the notes that follow indicate:

Python keywords may not be used as identifiers.

So the first part suggests Python keywords can be used, while the second part indicates they cannot. Testing suggests they cannot currently be used.

Suggested fix for documentation

Change the expr description to read:

You can refer to column names that are not valid Python variable names by surrounding them in backticks. Thus column names containing spaces or punctuation (besides underscores) or starting with digits must be surrounded by backticks. (For example, a column named "Area (cm^2)" would be referenced as Area (cm^2).) Column names which are Python keywords (like "list", "for", "import", etc) cannot be used.

@jpeacock29 jpeacock29 added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 30, 2020
@jbrockmendel jbrockmendel added expressions pd.eval, query and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 2, 2020
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Sep 10, 2020
@darshan-gandhi
Copy link

Hi, can I take up this issue and work on it? Thank you.

@ezebunandu
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants