3
3
import inspect
4
4
from contextlib import nullcontext
5
5
6
- cb_notify_dataframe_method_call = None
7
- cb_notify_series_method_call = None
8
6
cb_create_call_stack_context_manager = None
9
7
10
8
def register_dataframe_method (method ):
@@ -31,18 +29,15 @@ def __init__(self, pandas_obj):
31
29
@wraps (method )
32
30
def __call__ (self , * args , ** kwargs ):
33
31
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 ():
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
32
+ method_call_obj = cb_create_call_stack_context_manager (method .__name__ ) if cb_create_call_stack_context_manager else nullcontext ()
33
+ with method_call_obj :
34
+ if not isinstance (method_call_obj , nullcontext ):
35
+ new_args , new_kwargs = method_call_obj .handle_start_method_call (self ._obj , method .__name__ , method_signature , args , kwargs )
36
+ args = new_args [1 :]; kwargs = new_kwargs
42
37
43
38
ret = method (self ._obj , * args , ** kwargs )
44
39
45
- if method_call_obj :
40
+ if not isinstance ( method_call_obj , nullcontext ) :
46
41
method_call_obj .handle_end_method_call (ret )
47
42
48
43
return ret
@@ -69,18 +64,15 @@ def __init__(self, pandas_obj):
69
64
@wraps (method )
70
65
def __call__ (self , * args , ** kwargs ):
71
66
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 ():
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
67
+ method_call_obj = cb_create_call_stack_context_manager (method .__name__ ) if cb_create_call_stack_context_manager else nullcontext ()
68
+ with method_call_obj :
69
+ if not isinstance (method_call_obj , nullcontext ):
70
+ new_args , new_kwargs = method_call_obj .handle_start_method_call (self ._obj , method .__name__ , method_signature , args , kwargs )
71
+ args = new_args [1 :]; kwargs = new_kwargs
80
72
81
73
ret = method (self ._obj , * args , ** kwargs )
82
74
83
- if method_call_obj :
75
+ if not isinstance ( method_call_obj , nullcontext ) :
84
76
method_call_obj .handle_end_method_call (ret )
85
77
86
78
return ret
0 commit comments