Sitelet https://web.archive.org/web/20200912135357/https://github.com/pandas-dev/pandas/issues/35989
Skip to content
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

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

Open
jpeacock29 opened this issue Aug 30, 2020 · 1 comment

Comments

@jpeacock29
Copy link
Contributor

@jpeacock29 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.

@darshan-gandhi
Copy link

@darshan-gandhi darshan-gandhi commented Sep 11, 2020

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

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.