-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix bug when using df.query with "str.contains()" #25813
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25813 +/- ##
==========================================
+ Coverage 91.27% 91.27% +<.01%
==========================================
Files 173 173
Lines 53002 53002
==========================================
+ Hits 48375 48378 +3
+ Misses 4627 4624 -3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25813 +/- ##
==========================================
- Coverage 91.89% 91.27% -0.63%
==========================================
Files 175 173 -2
Lines 52509 53002 +493
==========================================
+ Hits 48255 48378 +123
- Misses 4254 4624 +370
Continue to review full report at Codecov.
|
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.
Can you add a whatsnew note for v0.25?
233a26b
to
087157c
Compare
@dtpc can you merge master and address comments? |
can you merge master and update |
@@ -412,6 +412,7 @@ Other | |||
|
|||
- Improved :class:`Timestamp` type checking in various datetime functions to prevent exceptions when using a subclassed `datetime` (:issue:`25851`) | |||
- Bug in :class:`Series` and :class:`DataFrame` repr where ``np.datetime64('NaT')`` and ``np.timedelta64('NaT')`` with ``dtype=object`` would be represented as ``NaN`` (:issue:`25445`) | |||
- Bug in :class:`BaseExprVisitor` which caused :func:`eval` expressions to fail when named keyword arguments were included within the expression string (:issue:`25813`) |
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.
Still needs a little work to make this user facing, i.e. only references items in the documented API (which BaseExprVisitor is not).
Would be better referencing the DataFrame.query method
@@ -1757,6 +1757,29 @@ def test_no_new_globals(self, engine, parser): | |||
assert gbls == gbls2 | |||
|
|||
|
|||
class TestEvalNamedKWargs(object): |
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 don't think we need a class here; OK to remove this and put tests at top level of module
df = pd.DataFrame([["I", "XYZ"], ["IJ", None]], columns=['A', 'B']) | ||
|
||
expected = df[df["A"].str.contains("J")] | ||
result = df.query("A.str.contains('J')", engine="python", |
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.
Any reason to not parametrize this for all engines?
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.
Yes, because engine=pandas
fails for this test (though that should have been explicit).
It's tries to hash a Series
object.
@@ -1757,6 +1757,29 @@ def test_no_new_globals(self, engine, parser): | |||
assert gbls == gbls2 | |||
|
|||
|
|||
class TestEvalNamedKWargs(object): | |||
# xref https://github.com/pandas-dev/pandas/issues/25813 |
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.
Just add #GH 25813
to the first line of the tests added here
@pandas-dev/pandas-core if someone wants to finish up |
this PR is superseded by #26426 |
git diff upstream/master -u -- "*.py" | flake8 --diff
Fixes bug in on line 588 of
pandas/core/computation/expr.py
:AttributeError: 'dict' object has no attribute 'append'
Also addresses the specific example in #22172
Example: