5
5
6
6
cb_notify_dataframe_method_call = None
7
7
cb_notify_series_method_call = None
8
+ cb_create_call_stack_context_manager = None
8
9
9
10
def register_dataframe_method (method ):
10
11
"""Register a function as a method attached to the Pandas DataFrame.
@@ -29,20 +30,22 @@ def __init__(self, pandas_obj):
29
30
30
31
@wraps (method )
31
32
def __call__ (self , * args , ** kwargs ):
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 )
36
- if method_call_obj :
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 )
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 ():
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 )
41
44
42
- if method_call_obj :
43
- method_call_obj .handle_end_method_call (ret )
45
+ if method_call_obj :
46
+ method_call_obj .handle_end_method_call (ret )
44
47
45
- return ret
48
+ return ret
46
49
47
50
register_dataframe_accessor (method .__name__ )(AccessorMethod )
48
51
@@ -65,20 +68,22 @@ def __init__(self, pandas_obj):
65
68
66
69
@wraps (method )
67
70
def __call__ (self , * args , ** kwargs ):
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 )
72
- if method_call_obj :
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 )
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 ():
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 )
77
82
78
- if method_call_obj :
79
- method_call_obj .handle_end_method_call (ret )
83
+ if method_call_obj :
84
+ method_call_obj .handle_end_method_call (ret )
80
85
81
- return ret
86
+ return ret
82
87
83
88
register_series_accessor (method .__name__ )(AccessorMethod )
84
89
0 commit comments