Skip to content

Commit 7257172

Browse files
committed
no need to keep call stack in pandas_flavor
1 parent 393282f commit 7257172

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

pandas_flavor/register.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import inspect
44
from contextlib import nullcontext
55

6-
cb_create_call_stack_context_manager = None
76
cb_notify_dataframe_method_call = None
87
cb_notify_series_method_call = None
98

@@ -30,22 +29,20 @@ def __init__(self, pandas_obj):
3029

3130
@wraps(method)
3231
def __call__(self, *args, **kwargs):
33-
global cb_create_call_stack_context_manager
34-
with cb_create_call_stack_context_manager(method.__name__) if cb_create_call_stack_context_manager else nullcontext() as sc:
35-
method_call_obj = None
36-
global cb_notify_dataframe_method_call
37-
if cb_notify_dataframe_method_call:
38-
method_call_obj = cb_notify_dataframe_method_call(self._obj, method.__name__, method_signature, args, kwargs)
39-
if method_call_obj:
40-
new_args, new_kwargs = method_call_obj.handle_start_method_call()
41-
args = new_args[1:]; kwargs = new_kwargs
42-
43-
ret = method(self._obj, *args, **kwargs)
44-
32+
method_call_obj = None
33+
global cb_notify_dataframe_method_call
34+
if cb_notify_dataframe_method_call:
35+
method_call_obj = cb_notify_dataframe_method_call(self._obj, method.__name__, method_signature, args, kwargs)
4536
if method_call_obj:
46-
method_call_obj.handle_end_method_call(ret)
47-
48-
return ret
37+
new_args, new_kwargs = method_call_obj.handle_start_method_call()
38+
args = new_args[1:]; kwargs = new_kwargs
39+
40+
ret = method(self._obj, *args, **kwargs)
41+
42+
if method_call_obj:
43+
method_call_obj.handle_end_method_call(ret)
44+
45+
return ret
4946

5047
register_dataframe_accessor(method.__name__)(AccessorMethod)
5148

@@ -68,22 +65,20 @@ def __init__(self, pandas_obj):
6865

6966
@wraps(method)
7067
def __call__(self, *args, **kwargs):
71-
global cb_create_call_stack_context_manager
72-
with cb_create_call_stack_context_manager(method.__name__) if cb_create_call_stack_context_manager else nullcontext() as sc:
73-
method_call_obj = None
74-
global cb_notify_series_method_call
75-
if cb_notify_series_method_call:
76-
method_call_obj = cb_notify_series_method_call(self._obj, method.__name__, method_signature, args, kwargs)
77-
if method_call_obj:
78-
new_args, new_kwargs = method_call_obj.handle_start_method_call()
79-
args = new_args[1:]; kwargs = new_kwargs
80-
81-
ret = method(self._obj, *args, **kwargs)
82-
68+
method_call_obj = None
69+
global cb_notify_series_method_call
70+
if cb_notify_series_method_call:
71+
method_call_obj = cb_notify_series_method_call(self._obj, method.__name__, method_signature, args, kwargs)
8372
if method_call_obj:
84-
method_call_obj.handle_end_method_call(ret)
85-
86-
return ret
73+
new_args, new_kwargs = method_call_obj.handle_start_method_call()
74+
args = new_args[1:]; kwargs = new_kwargs
75+
76+
ret = method(self._obj, *args, **kwargs)
77+
78+
if method_call_obj:
79+
method_call_obj.handle_end_method_call(ret)
80+
81+
return ret
8782

8883
register_series_accessor(method.__name__)(AccessorMethod)
8984

0 commit comments

Comments
 (0)