Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
if TYPE_CHECKING:
from collections.abc import Callable

_BOOLEAN_OPS = {"&": "and", "|": "or"}


def _rewrite_assign(tok: tuple[int, str]) -> tuple[int, str]:
"""
Expand Down Expand Up @@ -88,11 +90,8 @@ def _replace_booleans(tok: tuple[int, str]) -> tuple[int, str]:
"""
toknum, tokval = tok
if toknum == tokenize.OP:
if tokval == "&":
return tokenize.NAME, "and"
elif tokval == "|":
return tokenize.NAME, "or"
return toknum, tokval
if tokval in _BOOLEAN_OPS:
return tokenize.NAME, _BOOLEAN_OPS[tokval]
return toknum, tokval


Expand Down Expand Up @@ -512,8 +511,7 @@ def _maybe_evaluate_binop(
)

if self.engine != "pytables" and (
res.op in CMP_OPS_SYMS
and getattr(lhs, "is_datetime", False)
(res.op in CMP_OPS_SYMS and getattr(lhs, "is_datetime", False))
or getattr(rhs, "is_datetime", False)
):
# all date ops must be done in python bc numexpr doesn't work
Expand Down Expand Up @@ -699,7 +697,7 @@ def visit_Call(self, node, side=None, **kwargs):
if not isinstance(key, ast.keyword):
# error: "expr" has no attribute "id"
raise ValueError(
"keyword error in function call " f"'{node.func.id}'" # type: ignore[attr-defined]
f"keyword error in function call '{node.func.id}'" # type: ignore[attr-defined]
)

if key.arg:
Expand Down