Skip to content

Commit d7ffa02

Browse files
committed
replace old def udwf
1 parent cd972b5 commit d7ffa02

File tree

1 file changed

+1
-64
lines changed

1 file changed

+1
-64
lines changed

python/datafusion/udf.py

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -628,69 +628,6 @@ def __call__(self, *args: Expr) -> Expr:
628628

629629
@staticmethod
630630
def udwf(
631-
func: Callable[[], WindowEvaluator],
632-
input_types: pa.DataType | list[pa.DataType],
633-
return_type: pa.DataType,
634-
volatility: Volatility | str,
635-
name: Optional[str] = None,
636-
) -> WindowUDF:
637-
"""Create a new User-Defined Window Function.
638-
639-
If your :py:class:`WindowEvaluator` can be instantiated with no arguments, you
640-
can simply pass it's type as ``func``. If you need to pass additional arguments
641-
to it's constructor, you can define a lambda or a factory method. During runtime
642-
the :py:class:`WindowEvaluator` will be constructed for every instance in
643-
which this UDWF is used. The following examples are all valid.
644-
645-
.. code-block:: python
646-
647-
import pyarrow as pa
648-
649-
class BiasedNumbers(WindowEvaluator):
650-
def __init__(self, start: int = 0) -> None:
651-
self.start = start
652-
653-
def evaluate_all(self, values: list[pa.Array], num_rows: int) -> pa.Array:
654-
return pa.array([self.start + i for i in range(num_rows)])
655-
656-
def bias_10() -> BiasedNumbers:
657-
return BiasedNumbers(10)
658-
659-
udwf1 = udwf(BiasedNumbers, pa.int64(), pa.int64(), "immutable")
660-
udwf2 = udwf(bias_10, pa.int64(), pa.int64(), "immutable")
661-
udwf3 = udwf(lambda: BiasedNumbers(20), pa.int64(), pa.int64(), "immutable")
662-
663-
Args:
664-
func: A callable to create the window function.
665-
input_types: The data types of the arguments to ``func``.
666-
return_type: The data type of the return value.
667-
volatility: See :py:class:`Volatility` for allowed values.
668-
arguments: A list of arguments to pass in to the __init__ method for accum.
669-
name: A descriptive name for the function.
670-
671-
Returns:
672-
A user-defined window function.
673-
""" # noqa: W505, E501
674-
if not callable(func):
675-
msg = "`func` must be callable."
676-
raise TypeError(msg)
677-
if not isinstance(func(), WindowEvaluator):
678-
msg = "`func` must implement the abstract base class WindowEvaluator"
679-
raise TypeError(msg)
680-
if name is None:
681-
name = func().__class__.__qualname__.lower()
682-
if isinstance(input_types, pa.DataType):
683-
input_types = [input_types]
684-
return WindowUDF(
685-
name=name,
686-
func=func,
687-
input_types=input_types,
688-
return_type=return_type,
689-
volatility=volatility,
690-
)
691-
692-
@staticmethod
693-
def create_udwf(
694631
*args: Any, **kwargs: Any
695632
) -> Union[WindowUDF, Callable[[Callable[[], WindowEvaluator]], WindowUDF]]:
696633
"""Create a new User-Defined Window Function (UDWF).
@@ -788,4 +725,4 @@ def decorator(func: Callable[[], WindowEvaluator]) -> WindowUDF:
788725
# variables at the package root
789726
udf = ScalarUDF.udf
790727
udaf = AggregateUDF.udaf
791-
udwf = WindowUDF.create_udwf
728+
udwf = WindowUDF.udwf

0 commit comments

Comments
 (0)