-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: query modifies the frame when you compare with =
#8828
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
6794d8d
afe2d47
79e356d
3fe7951
67a44c5
70d8345
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 |
---|---|---|
|
@@ -15210,7 +15210,7 @@ class TestDataFrameQueryPythonPandas(TestDataFrameQueryNumExprPandas): | |
def setUpClass(cls): | ||
super(TestDataFrameQueryPythonPandas, cls).setUpClass() | ||
cls.engine = 'python' | ||
cls.parser = 'pandas' | ||
cls.parser = 'pandas_query' | ||
cls.frame = _frame.copy() | ||
|
||
def test_query_builtin(self): | ||
|
@@ -15225,6 +15225,16 @@ def test_query_builtin(self): | |
result = df.query('sin > 5', engine=engine, parser=parser) | ||
tm.assert_frame_equal(expected, result) | ||
|
||
def test_query_with_assign_statement(self): | ||
df = DataFrame({'a': [1, 2, 3], 'b': ['a', 'b', 'c']}) | ||
a_before = df['a'].copy() | ||
self.assertRaisesRegexp( | ||
NotImplementedError, "'Assign' nodes are not implemented", | ||
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. Not a big deal (and you don't need to fix it here), but in an ideal world this should be something closer to 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.
import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3], 'b': ['a', 'b', 'c']})
df.eval("{'x': 1}")
NotImplementedError
/home/me/.local/lib/python2.7/site-packages/pandas/computation/expr.pyc in visit(self, node, **kwargs)
312 method = 'visit_' + node.__class__.__name__
313 visitor = getattr(self, method)
--> 314 return visitor(node, **kwargs)
315
316 def visit_Module(self, node, **kwargs):
/home/me/.local/lib/python2.7/site-packages/pandas/computation/expr.pyc in f(self, *args, **kwargs)
203 def f(self, *args, **kwargs):
204 raise NotImplementedError("{0!r} nodes are not "
--> 205 "implemented".format(node_name))
206 return f
207
NotImplementedError: 'Dict' nodes are not implemented So at the moment it's just working like any other invalid query/eval. For this specific case I'll probably try to catch the exception within 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. the |
||
df.query, 'a=1', engine=self.engine, parser=self.parser | ||
) | ||
a_after = df['a'].copy() | ||
assert_series_equal(a_before, a_after) | ||
|
||
|
||
class TestDataFrameQueryPythonPython(TestDataFrameQueryNumExprPython): | ||
|
||
|
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 the issue number as a comment here