15
15
from pandas ._libs .tslibs import Timestamp
16
16
from pandas .compat .chainmap import DeepChainMap
17
17
18
- import pandas .core .computation as compu
19
- from pandas .core .computation .common import StringMixin
20
-
21
18
22
19
def _ensure_scope (
23
20
level , global_dict = None , local_dict = None , resolvers = (), target = None , ** kwargs
@@ -67,7 +64,8 @@ def _raw_hex_id(obj):
67
64
68
65
69
66
def _get_pretty_string (obj ):
70
- """Return a prettier version of obj
67
+ """
68
+ Return a prettier version of obj.
71
69
72
70
Parameters
73
71
----------
@@ -84,9 +82,9 @@ def _get_pretty_string(obj):
84
82
return sio .getvalue ()
85
83
86
84
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
90
88
and contexts added by pandas.
91
89
92
90
Parameters
@@ -105,7 +103,7 @@ class Scope(StringMixin):
105
103
temps : dict
106
104
"""
107
105
108
- __slots__ = "level" , "scope" , "target" , "temps"
106
+ __slots__ = [ "level" , "scope" , "target" , "resolvers" , " temps"]
109
107
110
108
def __init__ (
111
109
self , level , global_dict = None , local_dict = None , resolvers = (), target = None
@@ -163,7 +161,8 @@ def has_resolvers(self):
163
161
return bool (len (self .resolvers ))
164
162
165
163
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.
167
166
168
167
Parameters
169
168
----------
@@ -198,10 +197,14 @@ def resolve(self, key, is_local):
198
197
# e.g., df[df > 0]
199
198
return self .temps [key ]
200
199
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 )
202
204
203
205
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.
205
208
206
209
Parameters
207
210
----------
@@ -225,7 +228,8 @@ def swapkey(self, old_key, new_key, new_value=None):
225
228
return
226
229
227
230
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.
229
233
230
234
Parameters
231
235
----------
@@ -247,7 +251,8 @@ def _get_vars(self, stack, scopes):
247
251
del frame
248
252
249
253
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.
251
256
252
257
Parameters
253
258
----------
@@ -266,7 +271,8 @@ def update(self, level):
266
271
del stack [:], stack
267
272
268
273
def add_tmp (self , value ):
269
- """Add a temporary variable to the scope.
274
+ """
275
+ Add a temporary variable to the scope.
270
276
271
277
Parameters
272
278
----------
@@ -297,7 +303,8 @@ def ntemps(self):
297
303
298
304
@property
299
305
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
301
308
as a mapping.
302
309
303
310
Returns
0 commit comments