Skip to content

Commit 3fe7951

Browse files
committed
Add new specialized query parser
1 parent 79e356d commit 3fe7951

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pandas/computation/expr.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ def visitor(x, y):
589589

590590
_python_not_supported = frozenset(['Dict', 'Call', 'BoolOp', 'In', 'NotIn'])
591591
_numexpr_supported_calls = frozenset(_reductions + _mathops)
592+
_query_not_supported = frozenset(['Assign'])
592593

593594

594595
@disallow((_unsupported_nodes | _python_not_supported) -
@@ -602,6 +603,17 @@ def __init__(self, env, engine, parser,
602603
super(PandasExprVisitor, self).__init__(env, engine, parser, preparser)
603604

604605

606+
@disallow((_unsupported_nodes | _python_not_supported | _query_not_supported) -
607+
(_boolop_nodes | frozenset(['BoolOp', 'Attribute', 'In', 'NotIn',
608+
'Tuple'])))
609+
class PandasQueryExprVisitor(BaseExprVisitor):
610+
611+
def __init__(self, env, engine, parser,
612+
preparser=partial(_preparse, f=compose(_replace_locals,
613+
_replace_booleans))):
614+
super(PandasQueryExprVisitor, self).__init__(env, engine, parser, preparser)
615+
616+
605617
@disallow(_unsupported_nodes | _python_not_supported | frozenset(['Not']))
606618
class PythonExprVisitor(BaseExprVisitor):
607619

@@ -659,4 +671,5 @@ def names(self):
659671
return frozenset(term.name for term in com.flatten(self.terms))
660672

661673

662-
_parsers = {'python': PythonExprVisitor, 'pandas': PandasExprVisitor}
674+
_parsers = {'python': PythonExprVisitor, 'pandas': PandasExprVisitor,
675+
'pandas_query': PandasQueryExprVisitor}

0 commit comments

Comments
 (0)