From baf5cbba57230ffe0c3261a5bc5ed56bcd281e12 Mon Sep 17 00:00:00 2001 From: BharatDeva <278575558+BharatDeva@users.noreply.github.com> Date: Fri, 8 May 2026 19:28:51 -0500 Subject: [PATCH 1/2] fix: type scalar UDF returns as Arrow arrays --- python/datafusion/user_defined.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/datafusion/user_defined.py b/python/datafusion/user_defined.py index 848ab4cee..9a693e516 100644 --- a/python/datafusion/user_defined.py +++ b/python/datafusion/user_defined.py @@ -33,7 +33,7 @@ if TYPE_CHECKING: from _typeshed import CapsuleType as _PyCapsule - _R = TypeVar("_R", bound=pa.DataType) + _R = TypeVar("_R", bound=pa.Array) from collections.abc import Callable, Sequence @@ -125,7 +125,7 @@ def __init__( name: str, func: Callable[..., _R], input_fields: list[pa.Field], - return_field: _R, + return_field: pa.Field, volatility: Volatility | str, ) -> None: """Instantiate a scalar user-defined function (UDF). @@ -264,7 +264,7 @@ def _function( def _decorator( input_fields: Sequence[pa.DataType | pa.Field] | pa.DataType | pa.Field, - return_field: _R, + return_field: pa.DataType | pa.Field, volatility: Volatility | str, name: str | None = None, ) -> Callable: From f149f13940d4f12fe2fa598dbf6cfb0f172d2b5e Mon Sep 17 00:00:00 2001 From: BharatDeva <278575558+BharatDeva@users.noreply.github.com> Date: Sun, 2 Aug 2026 21:41:55 -0500 Subject: [PATCH 2/2] docs: clarify udf return_field type --- python/datafusion/user_defined.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/datafusion/user_defined.py b/python/datafusion/user_defined.py index 9a693e516..e44f9cec4 100644 --- a/python/datafusion/user_defined.py +++ b/python/datafusion/user_defined.py @@ -202,7 +202,8 @@ def udf(*args: Any, **kwargs: Any): # noqa: D417 input_fields (list[pa.Field | pa.DataType]): The data types or Fields of the arguments to ``func``. This list must be of the same length as the number of arguments. - return_field (_R): The field of the return value from the function. + return_field (pa.DataType | pa.Field): The field of the return value + from the function. volatility (Volatility | str): See `Volatility` for allowed values. name (Optional[str]): A descriptive name for the function.