Skip to content

Commit e66ad6c

Browse files
jbrockmendeljreback
authored andcommitted
cleanups, remove StringMixin (#27939)
1 parent 7a0bcc3 commit e66ad6c

File tree

8 files changed

+54
-54
lines changed

8 files changed

+54
-54
lines changed

pandas/compat/chainmap.py

-6
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,3 @@ def __delitem__(self, key):
1515
del mapping[key]
1616
return
1717
raise KeyError(key)
18-
19-
# override because the m parameter is introduced in Python 3.4
20-
def new_child(self, m=None):
21-
if m is None:
22-
m = {}
23-
return self.__class__(m, *self.maps)

pandas/core/computation/align.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pandas.errors import PerformanceWarning
1010

1111
import pandas as pd
12+
from pandas.core.base import PandasObject
1213
import pandas.core.common as com
1314
from pandas.core.computation.common import _result_type_many
1415

@@ -34,7 +35,7 @@ def _zip_axes_from_type(typ, new_axes):
3435

3536
def _any_pandas_objects(terms):
3637
"""Check a sequence of terms for instances of PandasObject."""
37-
return any(isinstance(term.value, pd.core.generic.PandasObject) for term in terms)
38+
return any(isinstance(term.value, PandasObject) for term in terms)
3839

3940

4041
def _filter_special_cases(f):
@@ -132,7 +133,8 @@ def _align(terms):
132133

133134

134135
def _reconstruct_object(typ, obj, axes, dtype):
135-
"""Reconstruct an object given its type, raw value, and possibly empty
136+
"""
137+
Reconstruct an object given its type, raw value, and possibly empty
136138
(None) axes.
137139
138140
Parameters
@@ -157,7 +159,7 @@ def _reconstruct_object(typ, obj, axes, dtype):
157159

158160
res_t = np.result_type(obj.dtype, dtype)
159161

160-
if not isinstance(typ, partial) and issubclass(typ, pd.core.generic.PandasObject):
162+
if not isinstance(typ, partial) and issubclass(typ, PandasObject):
161163
return typ(obj, dtype=res_t, **axes)
162164

163165
# special case for pathological things like ~True/~False

pandas/core/computation/common.py

-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,3 @@ def _remove_spaces_column_name(name):
3636

3737
class NameResolutionError(NameError):
3838
pass
39-
40-
41-
class StringMixin:
42-
# TODO: delete this class. Removing this ATM caused a failure.
43-
pass

pandas/core/computation/engines.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class NumExprClobberingError(NameError):
1717

1818

1919
def _check_ne_builtin_clash(expr):
20-
"""Attempt to prevent foot-shooting in a helpful way.
20+
"""
21+
Attempt to prevent foot-shooting in a helpful way.
2122
2223
Parameters
2324
----------
@@ -53,7 +54,8 @@ def convert(self):
5354
return printing.pprint_thing(self.expr)
5455

5556
def evaluate(self):
56-
"""Run the engine on the expression
57+
"""
58+
Run the engine on the expression.
5759
5860
This method performs alignment which is necessary no matter what engine
5961
is being used, thus its implementation is in the base class.
@@ -78,7 +80,8 @@ def _is_aligned(self):
7880

7981
@abc.abstractmethod
8082
def _evaluate(self):
81-
"""Return an evaluated expression.
83+
"""
84+
Return an evaluated expression.
8285
8386
Parameters
8487
----------
@@ -94,7 +97,6 @@ def _evaluate(self):
9497

9598

9699
class NumExprEngine(AbstractEngine):
97-
98100
"""NumExpr engine class"""
99101

100102
has_neg_frac = True
@@ -127,8 +129,8 @@ def _evaluate(self):
127129

128130

129131
class PythonEngine(AbstractEngine):
130-
131-
"""Evaluate an expression in Python space.
132+
"""
133+
Evaluate an expression in Python space.
132134
133135
Mostly for testing purposes.
134136
"""

pandas/core/computation/expr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141

4242

4343
def tokenize_string(source):
44-
"""Tokenize a Python source code string.
44+
"""
45+
Tokenize a Python source code string.
4546
4647
Parameters
4748
----------

pandas/core/computation/expressions.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ def _evaluate_numexpr(op, op_str, a, b, truediv=True, reversed=False, **eval_kwa
9999
result = None
100100

101101
if _can_use_numexpr(op, op_str, a, b, "evaluate"):
102-
try:
103-
104-
# we were originally called by a reversed op
105-
# method
106-
if reversed:
107-
a, b = b, a
102+
if reversed:
103+
# we were originally called by a reversed op method
104+
a, b = b, a
108105

109-
a_value = getattr(a, "values", a)
110-
b_value = getattr(b, "values", b)
106+
a_value = getattr(a, "values", a)
107+
b_value = getattr(b, "values", b)
108+
try:
111109
result = ne.evaluate(
112110
"a_value {op} b_value".format(op=op_str),
113111
local_dict={"a_value": a_value, "b_value": b_value},
@@ -138,11 +136,11 @@ def _where_numexpr(cond, a, b):
138136
result = None
139137

140138
if _can_use_numexpr(None, "where", a, b, "where"):
139+
cond_value = getattr(cond, "values", cond)
140+
a_value = getattr(a, "values", a)
141+
b_value = getattr(b, "values", b)
141142

142143
try:
143-
cond_value = getattr(cond, "values", cond)
144-
a_value = getattr(a, "values", a)
145-
b_value = getattr(b, "values", b)
146144
result = ne.evaluate(
147145
"where(cond_value, a_value, b_value)",
148146
local_dict={
@@ -209,7 +207,8 @@ def evaluate(op, op_str, a, b, use_numexpr=True, **eval_kwargs):
209207
Parameters
210208
----------
211209
op : the actual operand
212-
op_str : the string version of the op
210+
op_str : str
211+
The string version of the op.
213212
a : left operand
214213
b : right operand
215214
use_numexpr : bool, default True
@@ -224,11 +223,11 @@ def evaluate(op, op_str, a, b, use_numexpr=True, **eval_kwargs):
224223

225224
def where(cond, a, b, use_numexpr=True):
226225
"""
227-
Evaluate the where condition cond on a and b
226+
Evaluate the where condition cond on a and b.
228227
229228
Parameters
230229
----------
231-
cond : ndarray[bool]
230+
cond : np.ndarray[bool]
232231
a : return if cond is True
233232
b : return if cond is False
234233
use_numexpr : bool, default True

pandas/core/computation/ops.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ def isnumeric(dtype):
476476

477477

478478
class Div(BinOp):
479-
480-
"""Div operator to special case casting.
479+
"""
480+
Div operator to special case casting.
481481
482482
Parameters
483483
----------
@@ -508,8 +508,8 @@ def __init__(self, lhs, rhs, truediv, *args, **kwargs):
508508

509509

510510
class UnaryOp(Op):
511-
512-
"""Hold a unary operator and its operands
511+
"""
512+
Hold a unary operator and its operands.
513513
514514
Parameters
515515
----------

pandas/core/computation/scope.py

+22-15
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
from pandas._libs.tslibs import Timestamp
1616
from pandas.compat.chainmap import DeepChainMap
1717

18-
import pandas.core.computation as compu
19-
from pandas.core.computation.common import StringMixin
20-
2118

2219
def _ensure_scope(
2320
level, global_dict=None, local_dict=None, resolvers=(), target=None, **kwargs
@@ -67,7 +64,8 @@ def _raw_hex_id(obj):
6764

6865

6966
def _get_pretty_string(obj):
70-
"""Return a prettier version of obj
67+
"""
68+
Return a prettier version of obj.
7169
7270
Parameters
7371
----------
@@ -84,9 +82,9 @@ def _get_pretty_string(obj):
8482
return sio.getvalue()
8583

8684

87-
class Scope(StringMixin):
88-
89-
"""Object to hold scope, with a few bells to deal with some custom syntax
85+
class Scope:
86+
"""
87+
Object to hold scope, with a few bells to deal with some custom syntax
9088
and contexts added by pandas.
9189
9290
Parameters
@@ -105,7 +103,7 @@ class Scope(StringMixin):
105103
temps : dict
106104
"""
107105

108-
__slots__ = "level", "scope", "target", "temps"
106+
__slots__ = ["level", "scope", "target", "resolvers", "temps"]
109107

110108
def __init__(
111109
self, level, global_dict=None, local_dict=None, resolvers=(), target=None
@@ -163,7 +161,8 @@ def has_resolvers(self):
163161
return bool(len(self.resolvers))
164162

165163
def resolve(self, key, is_local):
166-
"""Resolve a variable name in a possibly local context
164+
"""
165+
Resolve a variable name in a possibly local context.
167166
168167
Parameters
169168
----------
@@ -198,10 +197,14 @@ def resolve(self, key, is_local):
198197
# e.g., df[df > 0]
199198
return self.temps[key]
200199
except KeyError:
201-
raise compu.ops.UndefinedVariableError(key, is_local)
200+
# runtime import because ops imports from scope
201+
from pandas.core.computation.ops import UndefinedVariableError
202+
203+
raise UndefinedVariableError(key, is_local)
202204

203205
def swapkey(self, old_key, new_key, new_value=None):
204-
"""Replace a variable name, with a potentially new value.
206+
"""
207+
Replace a variable name, with a potentially new value.
205208
206209
Parameters
207210
----------
@@ -225,7 +228,8 @@ def swapkey(self, old_key, new_key, new_value=None):
225228
return
226229

227230
def _get_vars(self, stack, scopes):
228-
"""Get specifically scoped variables from a list of stack frames.
231+
"""
232+
Get specifically scoped variables from a list of stack frames.
229233
230234
Parameters
231235
----------
@@ -247,7 +251,8 @@ def _get_vars(self, stack, scopes):
247251
del frame
248252

249253
def update(self, level):
250-
"""Update the current scope by going back `level` levels.
254+
"""
255+
Update the current scope by going back `level` levels.
251256
252257
Parameters
253258
----------
@@ -266,7 +271,8 @@ def update(self, level):
266271
del stack[:], stack
267272

268273
def add_tmp(self, value):
269-
"""Add a temporary variable to the scope.
274+
"""
275+
Add a temporary variable to the scope.
270276
271277
Parameters
272278
----------
@@ -297,7 +303,8 @@ def ntemps(self):
297303

298304
@property
299305
def full_scope(self):
300-
"""Return the full scope for use with passing to engines transparently
306+
"""
307+
Return the full scope for use with passing to engines transparently
301308
as a mapping.
302309
303310
Returns

0 commit comments

Comments
 (0)