Skip to content

Commit d19b47f

Browse files
authored
TYP: Create DeepChainMap from ChainMap.new_child in scope.py (#44769)
1 parent 482d66f commit d19b47f

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

pandas/core/computation/scope.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,13 @@ def __init__(
133133
# shallow copy here because we don't want to replace what's in
134134
# scope when we align terms (alignment accesses the underlying
135135
# numpy array of pandas objects)
136-
137-
# error: Incompatible types in assignment (expression has type
138-
# "ChainMap[str, Any]", variable has type "DeepChainMap[str, Any]")
139-
self.scope = self.scope.new_child( # type: ignore[assignment]
140-
(global_dict or frame.f_globals).copy()
141-
)
136+
scope_global = self.scope.new_child((global_dict or frame.f_globals).copy())
137+
self.scope = DeepChainMap(scope_global)
142138
if not isinstance(local_dict, Scope):
143-
# error: Incompatible types in assignment (expression has type
144-
# "ChainMap[str, Any]", variable has type "DeepChainMap[str, Any]")
145-
self.scope = self.scope.new_child( # type: ignore[assignment]
139+
scope_local = self.scope.new_child(
146140
(local_dict or frame.f_locals).copy()
147141
)
142+
self.scope = DeepChainMap(scope_local)
148143
finally:
149144
del frame
150145

@@ -257,9 +252,7 @@ def _get_vars(self, stack, scopes: list[str]) -> None:
257252
for scope, (frame, _, _, _, _, _) in variables:
258253
try:
259254
d = getattr(frame, "f_" + scope)
260-
# error: Incompatible types in assignment (expression has type
261-
# "ChainMap[str, Any]", variable has type "DeepChainMap[str, Any]")
262-
self.scope = self.scope.new_child(d) # type: ignore[assignment]
255+
self.scope = DeepChainMap(self.scope.new_child(d))
263256
finally:
264257
# won't remove it, but DECREF it
265258
# in Py3 this probably isn't necessary since frame won't be

0 commit comments

Comments
 (0)