Skip to content

REF/CLN: Move private method #24875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 15 additions & 5 deletions pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
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
11 changes: 0 additions & 11 deletions pandas/core/reshape/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,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)