Skip to content

Commit 7dd4252

Browse files
timsaucerclaude
andcommitted
docs: add doctest examples for sender ctx + UDF inlining toggle
Per CLAUDE.md, every Python function needs a docstring example. Adds examples to with_python_udf_inlining, set_sender_ctx, clear_sender_ctx, and get_sender_ctx. Also clarifies that with_python_udf_inlining returns a new SessionContext and leaves the original unchanged, matching the with_logical_extension_codec pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent eb3c194 commit 7dd4252

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

python/datafusion/context.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,15 @@ def with_python_udf_inlining(self, *, enabled: bool) -> SessionContext:
18001800
This setting narrows only :meth:`Expr.from_bytes`. Calling
18011801
:func:`pickle.loads` on untrusted bytes remains unsafe
18021802
regardless of the toggle.
1803+
1804+
Returns a new :class:`SessionContext` with the toggle applied;
1805+
the original session is unchanged.
1806+
1807+
Examples:
1808+
>>> from datafusion import SessionContext
1809+
>>> strict = SessionContext().with_python_udf_inlining(enabled=False)
1810+
>>> isinstance(strict, SessionContext)
1811+
True
18031812
"""
18041813
new_internal = self.ctx.with_python_udf_inlining(enabled)
18051814
new = SessionContext.__new__(SessionContext)

python/datafusion/ipc.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ def set_sender_ctx(ctx: SessionContext) -> None:
161161
slot, so worker threads on the driver may install their own contexts.
162162
Does not affect :meth:`Expr.to_bytes` calls that pass an explicit
163163
``ctx`` — those continue to use the supplied context.
164+
165+
Examples:
166+
>>> from datafusion import SessionContext
167+
>>> from datafusion.ipc import (
168+
... set_sender_ctx, get_sender_ctx, clear_sender_ctx,
169+
... )
170+
>>> driver = SessionContext().with_python_udf_inlining(enabled=False)
171+
>>> set_sender_ctx(driver)
172+
>>> get_sender_ctx() is driver
173+
True
174+
>>> clear_sender_ctx()
164175
"""
165176
_local.sender_ctx = ctx
166177

@@ -170,13 +181,30 @@ def clear_sender_ctx() -> None:
170181
171182
After clearing, pickled expressions fall back to the default codec
172183
(Python UDF inlining on).
184+
185+
Examples:
186+
>>> from datafusion import SessionContext
187+
>>> from datafusion.ipc import (
188+
... set_sender_ctx, clear_sender_ctx, get_sender_ctx,
189+
... )
190+
>>> set_sender_ctx(SessionContext())
191+
>>> clear_sender_ctx()
192+
>>> get_sender_ctx() is None
193+
True
173194
"""
174195
if hasattr(_local, "sender_ctx"):
175196
del _local.sender_ctx
176197

177198

178199
def get_sender_ctx() -> SessionContext | None:
179-
"""Return this driver's installed sender :class:`SessionContext`, or ``None``."""
200+
"""Return this driver's installed sender :class:`SessionContext`, or ``None``.
201+
202+
Examples:
203+
>>> from datafusion.ipc import get_sender_ctx, clear_sender_ctx
204+
>>> clear_sender_ctx()
205+
>>> get_sender_ctx() is None
206+
True
207+
"""
180208
return getattr(_local, "sender_ctx", None)
181209

182210

0 commit comments

Comments
 (0)