3
3
import inspect
4
4
from contextlib import nullcontext
5
5
6
- cb_create_call_stack_context_manager = None
6
+ method_call_ctx_factory = None
7
7
8
8
def register_dataframe_method (method ):
9
9
"""Register a function as a method attached to the Pandas DataFrame.
@@ -28,18 +28,18 @@ def __init__(self, pandas_obj):
28
28
29
29
@wraps (method )
30
30
def __call__ (self , * args , ** kwargs ):
31
- global cb_create_call_stack_context_manager
32
- method_call_obj = cb_create_call_stack_context_manager (method .__name__ , args , kwargs ) if cb_create_call_stack_context_manager else nullcontext ()
33
- with method_call_obj :
34
- if not isinstance (method_call_obj , nullcontext ):
31
+ global method_call_ctx_factory
32
+ method_call_ctx = method_call_ctx_factory (method .__name__ , args , kwargs ) if method_call_ctx_factory else nullcontext ()
33
+ with method_call_ctx :
34
+ if not isinstance (method_call_ctx , nullcontext ):
35
35
all_args = tuple ([self ._obj ] + list (args ))
36
- new_args , new_kwargs = method_call_obj .handle_start_method_call (method .__name__ , method_signature , all_args , kwargs )
36
+ new_args , new_kwargs = method_call_ctx .handle_start_method_call (method .__name__ , method_signature , all_args , kwargs )
37
37
args = new_args [1 :]; kwargs = new_kwargs
38
38
39
39
ret = method (self ._obj , * args , ** kwargs )
40
40
41
- if not isinstance (method_call_obj , nullcontext ):
42
- method_call_obj .handle_end_method_call (ret )
41
+ if not isinstance (method_call_ctx , nullcontext ):
42
+ method_call_ctx .handle_end_method_call (ret )
43
43
44
44
return ret
45
45
@@ -64,18 +64,18 @@ def __init__(self, pandas_obj):
64
64
65
65
@wraps (method )
66
66
def __call__ (self , * args , ** kwargs ):
67
- global cb_create_call_stack_context_manager
68
- method_call_obj = cb_create_call_stack_context_manager (method .__name__ , args , kwargs ) if cb_create_call_stack_context_manager else nullcontext ()
69
- with method_call_obj :
70
- if not isinstance (method_call_obj , nullcontext ):
67
+ global method_call_ctx_factory
68
+ method_call_ctx = method_call_ctx_factory (method .__name__ , args , kwargs ) if method_call_ctx_factory else nullcontext ()
69
+ with method_call_ctx :
70
+ if not isinstance (method_call_ctx , nullcontext ):
71
71
all_args = tuple ([self ._obj ] + list (args ))
72
- new_args , new_kwargs = method_call_obj .handle_start_method_call (method .__name__ , method_signature , all_args , kwargs )
72
+ new_args , new_kwargs = method_call_ctx .handle_start_method_call (method .__name__ , method_signature , all_args , kwargs )
73
73
args = new_args [1 :]; kwargs = new_kwargs
74
74
75
75
ret = method (self ._obj , * args , ** kwargs )
76
76
77
- if not isinstance (method_call_obj , nullcontext ):
78
- method_call_obj .handle_end_method_call (ret )
77
+ if not isinstance (method_call_ctx , nullcontext ):
78
+ method_call_ctx .handle_end_method_call (ret )
79
79
80
80
return ret
81
81
0 commit comments