Skip to content

Commit e6821c1

Browse files
committed
never mind last commit, we do need to track call stack in pandas_flavor, reverted
1 parent 7257172 commit e6821c1

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

pandas_flavor/register.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
cb_notify_dataframe_method_call = None
77
cb_notify_series_method_call = None
8+
cb_create_call_stack_context_manager = None
89

910
def register_dataframe_method(method):
1011
"""Register a function as a method attached to the Pandas DataFrame.
@@ -29,20 +30,22 @@ def __init__(self, pandas_obj):
2930

3031
@wraps(method)
3132
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)
4144

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)
4447

45-
return ret
48+
return ret
4649

4750
register_dataframe_accessor(method.__name__)(AccessorMethod)
4851

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

6669
@wraps(method)
6770
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)
7782

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)
8085

81-
return ret
86+
return ret
8287

8388
register_series_accessor(method.__name__)(AccessorMethod)
8489

0 commit comments

Comments
 (0)