-
-
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
Changes from all commits
8f22ebc
64004bc
087157c
36b0f43
63122dc
223e034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
# xref https://github.com/pandas-dev/pandas/issues/25813 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just add |
||
|
||
def test_eval_with_kwargs(self, engine, parser): | ||
def fn(x): | ||
return 2 * x | ||
result = pd.eval("fn(x=2)", engine=engine, parser=parser) | ||
assert result == 4 | ||
|
||
def test_query_str_contains(self, parser): | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because It's tries to hash a |
||
parser=parser) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
expected = df[df["B"].str.contains("Z", na=False)] | ||
result = df.query("B.str.contains('Z', na=False)", engine="python", | ||
parser=parser) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
@td.skip_if_no_ne | ||
def test_invalid_engine(): | ||
msg = 'Invalid engine \'asdf\' passed' | ||
|
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