diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 16f76651a65aa..3f12b1b21ff30 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -682,6 +682,7 @@ Other - Bug in :class:`.Styler` where copying from Jupyter dropped top left cell and misaligned headers (:issue:`12147`) - Bug in :meth:`DataFrame.equals`, :meth:`Series.equals`, :meth:`Index.equals` with object-dtype containing ``np.datetime64("NaT")`` or ``np.timedelta64("NaT")`` (:issue:`39650`) - Bug in :func:`pandas.util.show_versions` where console JSON output was not proper JSON (:issue:`39701`) +- Bug in :method:`DataFrame.query`, where "python" ``parser`` would raise NotImplementedError for == and != (:issue:`40436`) - Bug in :meth:`DataFrame.convert_dtypes` incorrectly raised ValueError when called on an empty DataFrame (:issue:`40393`) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index 02660539f4981..aee5c3442780a 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -384,8 +384,6 @@ class BaseExprVisitor(ast.NodeVisitor): unary_op_nodes_map = {k: v for k, v in zip(unary_ops, unary_op_nodes)} rewrite_map = { - ast.Eq: ast.In, - ast.NotEq: ast.NotIn, ast.In: ast.In, ast.NotIn: ast.NotIn, } diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index fdbf8a93ddddf..785ad1001f537 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -548,6 +548,13 @@ def test_query(self): df[df.a + df.b > df.b * df.c], ) + def test_query_equality(self): + engine, parser = self.engine, self.parser + df = DataFrame({"x": np.random.choice(["A", "B", "C"], size=20)}) + tm.assert_frame_equal( + df.query("x == 'A'", engine=engine, parser=parser), df[df.x == "A"] + ) + def test_query_index_with_name(self): engine, parser = self.engine, self.parser df = DataFrame(