Skip to content

Commit 7b9ced0

Browse files
committed
Enhance documentation for PyArrowArray type alias to clarify usage and improve type-checking
1 parent 16224e2 commit 7b9ced0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

python/datafusion/user_defined.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@
4141

4242
PyArrowArray = Union[pa.Array, pa.ChunkedArray]
4343
# Type alias for array batches exchanged with Python scalar UDFs.
44+
#
45+
# We need two related but different annotations here:
46+
# - `PyArrowArray` is the concrete union type (pa.Array | pa.ChunkedArray)
47+
# that is convenient for user-facing callables and casts. Use this when
48+
# annotating or checking values that may be either an Array or
49+
# a ChunkedArray.
50+
# - `PyArrowArrayT` is a constrained `TypeVar` over the two concrete
51+
# array flavors. Keeping a generic TypeVar allows helpers like
52+
# `_wrap_extension_value` and `_wrap_udf_function` to remain generic
53+
# and preserve the specific array "flavor" (Array vs ChunkedArray)
54+
# flowing through them, rather than collapsing everything to the
55+
# wide union. This improves type-checking and keeps return types
56+
# precise in the wrapper logic.
4457
PyArrowArrayT = TypeVar("PyArrowArrayT", pa.Array, pa.ChunkedArray)
4558

4659

0 commit comments

Comments
 (0)