Skip to content

Commit 393282f

Browse files
committed
call stack maintained in pandas_flavor via ctx manager cb
1 parent 8e1ee36 commit 393282f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

pandas_flavor/register.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import inspect
44
from contextlib import nullcontext
55

6+
cb_create_call_stack_context_manager = None
67
cb_notify_dataframe_method_call = None
78
cb_notify_series_method_call = None
8-
stack_counter_context = None
99

1010
def register_dataframe_method(method):
1111
"""Register a function as a method attached to the Pandas DataFrame.
@@ -30,13 +30,12 @@ def __init__(self, pandas_obj):
3030

3131
@wraps(method)
3232
def __call__(self, *args, **kwargs):
33-
global stack_counter_context_manager
34-
with stack_counter_context.get_sc() if stack_counter_context else nullcontext() as sc:
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() as sc:
3535
method_call_obj = None
3636
global cb_notify_dataframe_method_call
3737
if cb_notify_dataframe_method_call:
38-
stack_depth = sc.scf.level
39-
method_call_obj = cb_notify_dataframe_method_call(self._obj, method.__name__, method_signature, args, kwargs, stack_depth)
38+
method_call_obj = cb_notify_dataframe_method_call(self._obj, method.__name__, method_signature, args, kwargs)
4039
if method_call_obj:
4140
new_args, new_kwargs = method_call_obj.handle_start_method_call()
4241
args = new_args[1:]; kwargs = new_kwargs
@@ -69,13 +68,12 @@ def __init__(self, pandas_obj):
6968

7069
@wraps(method)
7170
def __call__(self, *args, **kwargs):
72-
global stack_counter_context_manager
73-
with stack_counter_context.get_sc() if stack_counter_context else nullcontext() as sc:
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() as sc:
7473
method_call_obj = None
7574
global cb_notify_series_method_call
7675
if cb_notify_series_method_call:
77-
stack_depth = sc.scf.level
78-
method_call_obj = cb_notify_series_method_call(self._obj, method.__name__, method_signature, args, kwargs, stack_depth)
76+
method_call_obj = cb_notify_series_method_call(self._obj, method.__name__, method_signature, args, kwargs)
7977
if method_call_obj:
8078
new_args, new_kwargs = method_call_obj.handle_start_method_call()
8179
args = new_args[1:]; kwargs = new_kwargs

0 commit comments

Comments
 (0)