|
18 | 18 | UndefinedVariableError, _arith_ops_syms, _bool_ops_syms, _cmp_ops_syms,
|
19 | 19 | _mathops, _reductions, _unary_ops_syms, is_term)
|
20 | 20 | from pandas.core.computation.scope import Scope
|
21 |
| -from pandas.core.reshape.util import compose |
22 | 21 |
|
23 | 22 | import pandas.io.formats.printing as printing
|
24 | 23 |
|
@@ -103,8 +102,19 @@ def _replace_locals(tok):
|
103 | 102 | return toknum, tokval
|
104 | 103 |
|
105 | 104 |
|
106 |
| -def _preparse(source, f=compose(_replace_locals, _replace_booleans, |
107 |
| - _rewrite_assign)): |
| 105 | +def _compose2(f, g): |
| 106 | + """Compose 2 callables""" |
| 107 | + return lambda *args, **kwargs: f(g(*args, **kwargs)) |
| 108 | + |
| 109 | + |
| 110 | +def _compose(*funcs): |
| 111 | + """Compose 2 or more callables""" |
| 112 | + assert len(funcs) > 1, 'At least 2 callables must be passed to compose' |
| 113 | + return reduce(_compose2, funcs) |
| 114 | + |
| 115 | + |
| 116 | +def _preparse(source, f=_compose(_replace_locals, _replace_booleans, |
| 117 | + _rewrite_assign)): |
108 | 118 | """Compose a collection of tokenization functions
|
109 | 119 |
|
110 | 120 | Parameters
|
@@ -701,8 +711,8 @@ def visitor(x, y):
|
701 | 711 | class PandasExprVisitor(BaseExprVisitor):
|
702 | 712 |
|
703 | 713 | def __init__(self, env, engine, parser,
|
704 |
| - preparser=partial(_preparse, f=compose(_replace_locals, |
705 |
| - _replace_booleans))): |
| 714 | + preparser=partial(_preparse, f=_compose(_replace_locals, |
| 715 | + _replace_booleans))): |
706 | 716 | super(PandasExprVisitor, self).__init__(env, engine, parser, preparser)
|
707 | 717 |
|
708 | 718 |
|
|
0 commit comments