-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the DataFrame.eval() docstring #20209
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: update the DataFrame.eval() docstring #20209
Conversation
On the beggining of the text of your PR, there is a space when using |
Fixed. |
pandas/core/frame.py
Outdated
3 8 | ||
4 7 | ||
dtype: int64 | ||
>>> df.eval('C = A + B') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a line before this saying "Assignment is allowed and by default the original DataFrame is not modiefied."
pandas/core/frame.py
Outdated
2 3 6 | ||
3 4 4 | ||
4 5 2 | ||
>>> df.eval('C = A + B', inplace=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And before this, say "use inplace=True
to modify the original DataFrame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestions, very good overall.
pandas/core/frame.py
Outdated
""" | ||
Evaluate expression in the context of the calling DataFrame instance. | ||
|
||
Evaluates a string describing operations on dataframe columns. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataframe --> DataFrame
pandas/core/frame.py
Outdated
|
||
Evaluates a string describing operations on dataframe columns. This | ||
allows `eval` to run arbitrary code, but remember to sanitize your | ||
inputs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be useful to state clearly that this will not evaluate expression within elements of the DataFrame, that it will only evaluate columns.
All fixes made, thanks for comments. |
pandas/core/frame.py
Outdated
not specific rows or elements). This allows `eval` to run arbitrary | ||
code, but remember to sanitize your inputs. | ||
|
||
This function calls `pandas.eval()` and is likely to be slower than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this, its not relevant
pandas/core/frame.py
Outdated
Evaluate expression in the context of the calling DataFrame instance. | ||
|
||
Evaluates a string describing operations on DataFrame columns (only, | ||
not specific rows or elements). This allows `eval` to run arbitrary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move the last sentence to the Notes section, and slightyl expand on 'sanitize' inputs.
Codecov Report
@@ Coverage Diff @@
## master #20209 +/- ##
=========================================
Coverage ? 91.7%
=========================================
Files ? 150
Lines ? 49165
Branches ? 0
=========================================
Hits ? 45087
Misses ? 4078
Partials ? 0
Continue to review full report at Codecov.
|
pandas/core/frame.py
Outdated
|
||
Notes | ||
----- | ||
For more details see the API documentation for :func:`~pandas.eval`. | ||
For detailed examples see :ref:`enhancing performance with eval | ||
<enhancingperf.eval>`. | ||
|
||
This function calls `pandas.eval()` and is likely to be slower than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meaningfully slower than pd.eval
? We don't seem to do much before handing it off, so if you're doing anything meaningfully expensive in the eval
, there shouldn't be much overhead. I'd prefer to remove this unless there's a significant difference.
pandas/core/frame.py
Outdated
pandas.DataFrame.query | ||
pandas.DataFrame.assign | ||
pandas.eval | ||
pandas.DataFrame.query : Evaluates a boolean expression to query the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe DataFrame.query
and DataFrame.assign
will work. You will need pandas
in pandas.eval
.
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks: