8
8
9
9
method_call_ctx_factory = None
10
10
11
+
11
12
def handle_pandas_extention_call (method , method_signature , obj , args , kwargs ):
12
13
"""
13
14
This function is called when the user calls the registered method on pandas dataframe object.
@@ -19,7 +20,7 @@ def handle_pandas_extention_call(method, method_signature, obj, args, kwargs):
19
20
In this case the implementation calls the registered method with unmodified args and kwargs and returns underlying method result.
20
21
21
22
b) case when *method_call_ctx_factory* is not None
22
- In this case *method_call_ctx_factory* expected to refer to the function to create the context object. The context object will be used
23
+ In this case *method_call_ctx_factory* expected to refer to the function to create the context object. The context object will be used
23
24
to process inputs and outputs of *method* call. It is also possible that the context object method *handle_start_method_call*
24
25
will modify original args and kwargs before *method* call.
25
26
@@ -31,11 +32,11 @@ def handle_pandas_extention_call(method, method_signature, obj, args, kwargs):
31
32
32
33
Parameters
33
34
----------
34
- method :
35
+ method :
35
36
method object as registered by decorator register_dataframe_method (or register_series_method)
36
- method_signature :
37
+ method_signature :
37
38
signature of method as returned by inspect.signature
38
- obj :
39
+ obj :
39
40
pandas object - Dataframe or Series
40
41
*args : list
41
42
The arguments to pass to the registered method.
@@ -59,10 +60,7 @@ def handle_pandas_extention_call(method, method_signature, obj, args, kwargs):
59
60
with method_call_ctx :
60
61
if not isinstance (method_call_ctx , nullcontext ):
61
62
all_args = tuple ([obj ] + list (args ))
62
- (
63
- new_args ,
64
- new_kwargs ,
65
- ) = method_call_ctx .handle_start_method_call (
63
+ (new_args , new_kwargs ,) = method_call_ctx .handle_start_method_call (
66
64
method .__name__ , method_signature , all_args , kwargs
67
65
)
68
66
args = new_args [1 :]
@@ -73,7 +71,8 @@ def handle_pandas_extention_call(method, method_signature, obj, args, kwargs):
73
71
if not isinstance (method_call_ctx , nullcontext ):
74
72
method_call_ctx .handle_end_method_call (ret )
75
73
76
- return ret
74
+ return ret
75
+
77
76
78
77
def register_dataframe_method (method ):
79
78
"""Register a function as a method attached to the Pandas DataFrame.
@@ -98,7 +97,9 @@ def __init__(self, pandas_obj):
98
97
99
98
@wraps (method )
100
99
def __call__ (self , * args , ** kwargs ):
101
- return handle_pandas_extention_call (method , method_signature , self ._obj , args , kwargs )
100
+ return handle_pandas_extention_call (
101
+ method , method_signature , self ._obj , args , kwargs
102
+ )
102
103
103
104
register_dataframe_accessor (method .__name__ )(AccessorMethod )
104
105
@@ -121,7 +122,9 @@ def __init__(self, pandas_obj):
121
122
122
123
@wraps (method )
123
124
def __call__ (self , * args , ** kwargs ):
124
- return handle_pandas_extention_call (method , method_signature , self ._obj , args , kwargs )
125
+ return handle_pandas_extention_call (
126
+ method , method_signature , self ._obj , args , kwargs
127
+ )
125
128
126
129
register_series_accessor (method .__name__ )(AccessorMethod )
127
130
0 commit comments