Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
REF/CLN: Move private method (pandas-dev#24875)
  • Loading branch information
mroeschke authored and Pingviinituutti committed Feb 28, 2019
1 parent 5c24756 commit 99de527
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
20 changes: 15 additions & 5 deletions pandas/core/computation/expr.py
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
13 changes: 0 additions & 13 deletions 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
Expand Down Expand Up @@ -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)

0 comments on commit 99de527

Please sign in to comment.