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

updating df.query and df.eval docstrings. resolves #16283 #58749

Merged
merged 6 commits into from
May 31, 2024

Conversation

mutricyl
Copy link
Contributor

This is a docstring improvement suggested in #16283 issue discussion. df.eval and df.query are updated for consistency and adding exemples with @ usage for local variables

Comment on lines 4660 to 4668
You can refer to column names that are not valid Python variable names
by surrounding them in backticks. Thus, column names containing spaces
or punctuations (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.

For example, if one of your columns is called ``a a`` and you want
to sum it with ``b``, your query should be ```a a` + b``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you demonstrate this in the Example section instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added one example in the Example section. Note that above wording is coming from query function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove all this explanation now that it's explained in the examples section

@mroeschke mroeschke added Docs expressions pd.eval, query labels May 17, 2024
2 3 6 9
3 4 4 8
4 5 2 7
A B C C C
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These headers don't look correct anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked and it looks correct

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the examples here you can see 5 column labels for 4 columns: https://pandas.pydata.org/preview/pandas-dev/pandas/58749/docs/reference/api/pandas.DataFrame.eval.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial example dataframe contains 3 columns: A, B and C C. The eval method will add a fourth column named C in the resulting dataframe for this example.
Repr of the dataframe does not make the separation of columns obvious when columns contains spaces. It is like there is 3 columns C when you actually have C C and C.

To make the example cristal clear I may change C C by C&C and update the examples to add columns with names differents than C.

Do you want me to update also query examples as C C is actually coming from there ??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the example cristal clear I may change C C by C&C and update the examples to add columns with names differents than C.

Ah yes that would be great. Sorry I didn't backtrack to see the context of the original columns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall I update query as well ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please

@mutricyl mutricyl requested a review from mroeschke May 23, 2024 07:30
@mroeschke
Copy link
Member

/preview

Copy link
Contributor

Website preview of this PR available at: https://pandas.pydata.org/preview/pandas-dev/pandas/58749/

@mroeschke mroeschke added this to the 3.0 milestone May 31, 2024
@mroeschke mroeschke merged commit a2a78d3 into pandas-dev:main May 31, 2024
47 checks passed
@mroeschke
Copy link
Member

Thanks @mutricyl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs expressions pd.eval, query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

df.eval does not see globals
2 participants