From 99de527cda991aa03a637ea5875b8ea61c30e949 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Tue, 22 Jan 2019 06:49:32 -0800 Subject: [PATCH] REF/CLN: Move private method (#24875) --- pandas/core/computation/expr.py | 20 +++++++++++++++----- pandas/core/reshape/util.py | 13 ------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index 9a44198ba3b862..d840bf6ae71a2e 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -18,7 +18,6 @@ UndefinedVariableError, _arith_ops_syms, _bool_ops_syms, _cmp_ops_syms, _mathops, _reductions, _unary_ops_syms, is_term) from pandas.core.computation.scope import Scope -from pandas.core.reshape.util import compose import pandas.io.formats.printing as printing @@ -103,8 +102,19 @@ def _replace_locals(tok): return toknum, tokval -def _preparse(source, f=compose(_replace_locals, _replace_booleans, - _rewrite_assign)): +def _compose2(f, g): + """Compose 2 callables""" + return lambda *args, **kwargs: f(g(*args, **kwargs)) + + +def _compose(*funcs): + """Compose 2 or more callables""" + assert len(funcs) > 1, 'At least 2 callables must be passed to compose' + return reduce(_compose2, funcs) + + +def _preparse(source, f=_compose(_replace_locals, _replace_booleans, + _rewrite_assign)): """Compose a collection of tokenization functions Parameters @@ -701,8 +711,8 @@ def visitor(x, y): class PandasExprVisitor(BaseExprVisitor): def __init__(self, env, engine, parser, - preparser=partial(_preparse, f=compose(_replace_locals, - _replace_booleans))): + preparser=partial(_preparse, f=_compose(_replace_locals, + _replace_booleans))): super(PandasExprVisitor, self).__init__(env, engine, parser, preparser) diff --git a/pandas/core/reshape/util.py b/pandas/core/reshape/util.py index 7f43a0e9719b88..9d4135a7f310e6 100644 --- a/pandas/core/reshape/util.py +++ b/pandas/core/reshape/util.py @@ -1,7 +1,5 @@ import numpy as np -from pandas.compat import reduce - from pandas.core.dtypes.common import is_list_like from pandas.core import common as com @@ -57,14 +55,3 @@ def cartesian_product(X): return [np.tile(np.repeat(np.asarray(com.values_from_object(x)), b[i]), np.product(a[i])) for i, x in enumerate(X)] - - -def _compose2(f, g): - """Compose 2 callables""" - return lambda *args, **kwargs: f(g(*args, **kwargs)) - - -def compose(*funcs): - """Compose 2 or more callables""" - assert len(funcs) > 1, 'At least 2 callables must be passed to compose' - return reduce(_compose2, funcs)