From b212fabc5ad6a03256779d635efa5bfeabec54e6 Mon Sep 17 00:00:00 2001 From: Kashif Khan <200~361477+kashifkhan@users.noreply.github.com> Date: Sun, 5 Dec 2021 11:53:38 -0600 Subject: [PATCH 1/4] TYP: create DeepChainMap from ChainMap.new_child --- pandas/core/computation/scope.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index 426cd8fd81f28..ff3f8b8ae444d 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -134,17 +134,9 @@ def __init__( # 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() - ) + self.scope = DeepChainMap(self.scope.new_child( (global_dict or frame.f_globals).copy())) 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] - (local_dict or frame.f_locals).copy() - ) + self.scope = DeepChainMap( self.scope.new_child((local_dict or frame.f_locals).copy())) finally: del frame @@ -257,9 +249,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 From 20a33e06ac28aefad2f2ea6e097a60bf004dab3a Mon Sep 17 00:00:00 2001 From: Kashif Khan <200~361477+kashifkhan@users.noreply.github.com> Date: Sun, 5 Dec 2021 12:21:21 -0600 Subject: [PATCH 2/4] fix some formatting issues --- pandas/core/computation/scope.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index ff3f8b8ae444d..0a8e7c3702d08 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -133,10 +133,15 @@ 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) - - self.scope = DeepChainMap(self.scope.new_child( (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): - self.scope = DeepChainMap( self.scope.new_child((local_dict or frame.f_locals).copy())) + scope_local = self.scope.new_child( + (local_dict or frame.f_locals).copy() + ) + self.scope = DeepChainMap(scope_local) finally: del frame From 52796ce43f20796f8815504e0b243a48b8d381e1 Mon Sep 17 00:00:00 2001 From: Kashif Khan <200~361477+kashifkhan@users.noreply.github.com> Date: Sun, 5 Dec 2021 12:24:47 -0600 Subject: [PATCH 3/4] fix some more formatting --- pandas/core/computation/scope.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index 0a8e7c3702d08..64955f9341889 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -135,12 +135,12 @@ def __init__( # numpy array of pandas objects) scope_global = self.scope.new_child( (global_dict or frame.f_globals).copy() - ) + ) self.scope = DeepChainMap(scope_global) if not isinstance(local_dict, Scope): scope_local = self.scope.new_child( (local_dict or frame.f_locals).copy() - ) + ) self.scope = DeepChainMap(scope_local) finally: del frame From 79e4d4c69a6d3afec2ce57df20738f93f7e7488d Mon Sep 17 00:00:00 2001 From: Kashif Khan <200~361477+kashifkhan@users.noreply.github.com> Date: Sun, 5 Dec 2021 16:58:20 -0600 Subject: [PATCH 4/4] Fix pre-commit errors --- pandas/core/computation/scope.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index 64955f9341889..d4fbe226a3ae2 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -133,9 +133,7 @@ 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) - scope_global = self.scope.new_child( - (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): scope_local = self.scope.new_child(