Skip to content

TYP: Create DeepChainMap from ChainMap.new_child in scope.py #44769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions pandas/core/computation/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,13 @@ def __init__(
# shallow copy here because we don't want to replace what's in
# scope when we align terms (alignment accesses the underlying
# numpy array of pandas objects)

# error: Incompatible types in assignment (expression has type
# "ChainMap[str, Any]", variable has type "DeepChainMap[str, Any]")
self.scope = self.scope.new_child( # type: ignore[assignment]
(global_dict or frame.f_globals).copy()
)
scope_global = self.scope.new_child((global_dict or frame.f_globals).copy())
self.scope = DeepChainMap(scope_global)
if not isinstance(local_dict, Scope):
# error: Incompatible types in assignment (expression has type
# "ChainMap[str, Any]", variable has type "DeepChainMap[str, Any]")
self.scope = self.scope.new_child( # type: ignore[assignment]
scope_local = self.scope.new_child(
(local_dict or frame.f_locals).copy()
)
self.scope = DeepChainMap(scope_local)
finally:
del frame

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