Skip to content

Commit b9b462c

Browse files
jbrockmendeljreback
authored andcommitted
CLN: parts of #29667 (#29677)
1 parent 5a0f7e9 commit b9b462c

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

pandas/core/computation/eval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from pandas.core.computation.engines import _engines
1313
from pandas.core.computation.expr import Expr, _parsers, tokenize_string
14-
from pandas.core.computation.scope import _ensure_scope
14+
from pandas.core.computation.scope import ensure_scope
1515

1616
from pandas.io.formats.printing import pprint_thing
1717

@@ -309,7 +309,7 @@ def eval(
309309
_check_for_locals(expr, level, parser)
310310

311311
# get our (possibly passed-in) scope
312-
env = _ensure_scope(
312+
env = ensure_scope(
313313
level + 1,
314314
global_dict=global_dict,
315315
local_dict=local_dict,

pandas/core/computation/ops.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ class Op:
197197
Hold an operator of arbitrary arity.
198198
"""
199199

200-
def __init__(self, op, operands, *args, **kwargs):
200+
op: str
201+
202+
def __init__(self, op: str, operands, *args, **kwargs):
201203
self.op = _bool_op_map.get(op, op)
202204
self.operands = operands
203205
self.encoding = kwargs.get("encoding", None)

pandas/core/computation/pytables.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313

1414
import pandas as pd
1515
import pandas.core.common as com
16-
from pandas.core.computation import expr, ops
16+
from pandas.core.computation import expr, ops, scope as _scope
1717
from pandas.core.computation.common import _ensure_decoded
1818
from pandas.core.computation.expr import BaseExprVisitor
1919
from pandas.core.computation.ops import UndefinedVariableError, is_term
2020

2121
from pandas.io.formats.printing import pprint_thing, pprint_thing_encoded
2222

2323

24-
class Scope(expr.Scope):
24+
class Scope(_scope.Scope):
2525
__slots__ = ("queryables",)
2626

27-
def __init__(self, level, global_dict=None, local_dict=None, queryables=None):
27+
def __init__(self, level: int, global_dict=None, local_dict=None, queryables=None):
2828
super().__init__(level + 1, global_dict=global_dict, local_dict=local_dict)
2929
self.queryables = queryables or dict()
3030

@@ -40,6 +40,7 @@ def __init__(self, name, env, side=None, encoding=None):
4040
def _resolve_name(self):
4141
# must be a queryables
4242
if self.side == "left":
43+
# Note: The behavior of __new__ ensures that self.name is a str here
4344
if self.name not in self.env.queryables:
4445
raise NameError("name {name!r} is not defined".format(name=self.name))
4546
return self.name

pandas/core/computation/scope.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
from pandas.compat.chainmap import DeepChainMap
1717

1818

19-
def _ensure_scope(
20-
level, global_dict=None, local_dict=None, resolvers=(), target=None, **kwargs
21-
):
19+
def ensure_scope(
20+
level: int, global_dict=None, local_dict=None, resolvers=(), target=None, **kwargs
21+
) -> "Scope":
2222
"""Ensure that we are grabbing the correct scope."""
2323
return Scope(
2424
level + 1,
@@ -119,7 +119,7 @@ def __init__(
119119
self.scope.update(local_dict.scope)
120120
if local_dict.target is not None:
121121
self.target = local_dict.target
122-
self.update(local_dict.level)
122+
self._update(local_dict.level)
123123

124124
frame = sys._getframe(self.level)
125125

@@ -251,7 +251,7 @@ def _get_vars(self, stack, scopes):
251251
# scope after the loop
252252
del frame
253253

254-
def update(self, level: int):
254+
def _update(self, level: int):
255255
"""
256256
Update the current scope by going back `level` levels.
257257

0 commit comments

Comments
 (0)