From 29e3e4589421b1c708150be76940cdf3c4b3d3e9 Mon Sep 17 00:00:00 2001 From: tp Date: Tue, 21 May 2019 21:02:25 +0200 Subject: [PATCH] CLN: Remove StringMixin from pandas.core.computation --- pandas/core/computation/expr.py | 5 ++--- pandas/core/computation/ops.py | 17 +++++++---------- pandas/core/computation/pytables.py | 9 ++++----- pandas/core/computation/scope.py | 13 ++++++------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index 32bd34c4db7d7..8f37738964d60 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -13,7 +13,6 @@ import pandas as pd from pandas.core import common as com -from pandas.core.base import StringMixin from pandas.core.computation.common import ( _BACKTICK_QUOTED_STRING, _remove_spaces_column_name) from pandas.core.computation.ops import ( @@ -701,7 +700,7 @@ def __init__(self, env, engine, parser, preparser=lambda x: x): super().__init__(env, engine, parser, preparser=preparser) -class Expr(StringMixin): +class Expr: """Object encapsulating an expression. @@ -732,7 +731,7 @@ def assigner(self): def __call__(self): return self.terms(self.env) - def __str__(self): + def __repr__(self): return printing.pprint_thing(self.terms) def __len__(self): diff --git a/pandas/core/computation/ops.py b/pandas/core/computation/ops.py index fd96739f4da76..941ce3fc1aa87 100644 --- a/pandas/core/computation/ops.py +++ b/pandas/core/computation/ops.py @@ -12,7 +12,6 @@ from pandas.core.dtypes.common import is_list_like, is_scalar -from pandas.core.base import StringMixin import pandas.core.common as com from pandas.core.computation.common import _ensure_decoded, _result_type_many from pandas.core.computation.scope import _DEFAULT_GLOBALS @@ -46,7 +45,7 @@ def __init__(self, name, is_local): super().__init__(msg.format(name)) -class Term(StringMixin): +class Term: def __new__(cls, name, env, side=None, encoding=None): klass = Constant if not isinstance(name, str) else cls @@ -67,7 +66,7 @@ def __init__(self, name, env, side=None, encoding=None): def local_name(self): return self.name.replace(_LOCAL_TAG, '') - def __str__(self): + def __repr__(self): return pprint_thing(self.name) def __call__(self, *args, **kwargs): @@ -166,16 +165,14 @@ def _resolve_name(self): def name(self): return self.value - def __str__(self): - # in python 2 str() of float - # can truncate shorter than repr() + def __repr__(self): return repr(self.name) _bool_op_map = {'not': '~', 'and': '&', 'or': '|'} -class Op(StringMixin): +class Op: """Hold an operator of arbitrary arity """ @@ -188,7 +185,7 @@ def __init__(self, op, operands, *args, **kwargs): def __iter__(self): return iter(self.operands) - def __str__(self): + def __repr__(self): """Print a generic n-ary operator and its operands using infix notation""" # recurse over the operands @@ -506,7 +503,7 @@ def __call__(self, env): operand = self.operand(env) return self.func(operand) - def __str__(self): + def __repr__(self): return pprint_thing('{0}({1})'.format(self.op, self.operand)) @property @@ -531,7 +528,7 @@ def __call__(self, env): with np.errstate(all='ignore'): return self.func.func(*operands) - def __str__(self): + def __repr__(self): operands = map(str, self.operands) return pprint_thing('{0}({1})'.format(self.op, ','.join(operands))) diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index 2a762b5ee24b6..8b6655608dad6 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -11,7 +11,6 @@ from pandas.core.dtypes.common import is_list_like import pandas as pd -from pandas.core.base import StringMixin import pandas.core.common as com from pandas.core.computation import expr, ops from pandas.core.computation.common import _ensure_decoded @@ -36,7 +35,7 @@ class Term(ops.Term): def __new__(cls, name, env, side=None, encoding=None): klass = Constant if not isinstance(name, str) else cls - supr_new = StringMixin.__new__ + supr_new = object.__new__ return supr_new(klass) def __init__(self, name, env, side=None, encoding=None): @@ -230,7 +229,7 @@ def convert_values(self): class FilterBinOp(BinOp): - def __str__(self): + def __repr__(self): return pprint_thing("[Filter : [{lhs}] -> [{op}]" .format(lhs=self.filter[0], op=self.filter[1])) @@ -302,7 +301,7 @@ def evaluate(self): class ConditionBinOp(BinOp): - def __str__(self): + def __repr__(self): return pprint_thing("[Condition : [{cond}]]" .format(cond=self.condition)) @@ -549,7 +548,7 @@ def __init__(self, where, queryables=None, encoding=None, scope_level=0): encoding=encoding) self.terms = self.parse() - def __str__(self): + def __repr__(self): if self.terms is not None: return pprint_thing(self.terms) return pprint_thing(self.expr) diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index 729acdc52e24a..4911488b007a4 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -15,7 +15,6 @@ from pandas._libs.tslibs import Timestamp from pandas.compat.chainmap import DeepChainMap -from pandas.core.base import StringMixin import pandas.core.computation as compu @@ -78,7 +77,7 @@ def _get_pretty_string(obj): return sio.getvalue() -class Scope(StringMixin): +class Scope: """Object to hold scope, with a few bells to deal with some custom syntax and contexts added by pandas. @@ -135,13 +134,13 @@ def __init__(self, level, global_dict=None, local_dict=None, resolvers=(), self.resolvers = DeepChainMap(*resolvers) self.temps = {} - def __str__(self): + def __repr__(self): scope_keys = _get_pretty_string(list(self.scope.keys())) res_keys = _get_pretty_string(list(self.resolvers.keys())) - unicode_str = '{name}(scope={scope_keys}, resolvers={res_keys})' - return unicode_str.format(name=type(self).__name__, - scope_keys=scope_keys, - res_keys=res_keys) + template = '{name}(scope={scope_keys}, resolvers={res_keys})' + return template.format(name=type(self).__name__, + scope_keys=scope_keys, + res_keys=res_keys) @property def has_resolvers(self):