Skip to content

Commit 543b048

Browse files
committed
fixed typo in handle_pandas_extension_call. also, branching logic changed to clearly direct default way to call pandas methods in the case when method_call_ctx_factory is default None - corresponds to the case of pandas_flavor used without method tracing mechanism provided by method_call_ctx_factory
1 parent 6456287 commit 543b048

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

pandas_flavor/register.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,19 @@ def handle_end_method_call(self, ret: object) -> None:
7070
"""
7171

7272
global method_call_ctx_factory
73-
74-
method_call_ctx = (
75-
method_call_ctx_factory(method.__name__, args, kwargs)
76-
if method_call_ctx_factory
77-
else nullcontext()
78-
)
79-
80-
with method_call_ctx:
81-
if not isinstance(method_call_ctx, nullcontext):
73+
with method_call_ctx_factory(method.__name__, args, kwargs) as method_call_ctx:
74+
if method_call_ctx is None: # nullcontext __enter__ returns None
75+
ret = method(obj, *args, **kwargs)
76+
else:
8277
all_args = tuple([obj] + list(args))
8378
(new_args, new_kwargs,) = method_call_ctx.handle_start_method_call(
8479
method.__name__, method_signature, all_args, kwargs
8580
)
8681
args = new_args[1:]
8782
kwargs = new_kwargs
8883

89-
ret = method(obj, *args, **kwargs)
84+
ret = method(obj, *args, **kwargs)
9085

91-
if not isinstance(method_call_ctx, nullcontext):
9286
method_call_ctx.handle_end_method_call(ret)
9387

9488
return ret
@@ -117,7 +111,11 @@ def __init__(self, pandas_obj):
117111

118112
@wraps(method)
119113
def __call__(self, *args, **kwargs):
120-
return handle_pandas_extention_call(
114+
global method_call_ctx_factory
115+
if method_call_ctx_factory is None:
116+
return method(obj, *args, **kwargs)
117+
118+
return handle_pandas_extension_call(
121119
method, method_signature, self._obj, args, kwargs
122120
)
123121

@@ -142,7 +140,11 @@ def __init__(self, pandas_obj):
142140

143141
@wraps(method)
144142
def __call__(self, *args, **kwargs):
145-
return handle_pandas_extention_call(
143+
global method_call_ctx_factory
144+
if method_call_ctx_factory is None:
145+
return method(obj, *args, **kwargs)
146+
147+
return handle_pandas_extension_call(
146148
method, method_signature, self._obj, args, kwargs
147149
)
148150

0 commit comments

Comments
 (0)