Skip to main content
Version: 1.4.0

tabsdata.tableframe.udf.function

UDF
UDF.columns
UDF.on_batchCreating UDFs: 1.
UDF.on_elementCreating UDFs: 1.
UDF.with_columns

UDF

class UDF(
output_columns: list[tuple[str, DataTypeClass | DataType]] | tuple[str, DataTypeClass | DataType],
)

Bases: ABC

columns
def columns() -> list[tuple[str, DataTypeClass | DataType]]

on_batch
def on_batch(series: list[Series]) -> list[Series]

Creating UDFs:

  1. Subclass :class:tabsdata.tableframe.udf.function.UDF.
  2. Implement __init__ to call super().__init__(output_columns) where output_columns is a tuple or list of tuples (name, data type) specifying the UDF default output schema (column names and data types). Each tuple must contain a column name (string) and a data type (DataType).
  3. Override exactly one of on_batch or on_element, to implement the UDF function logic.
  4. Return a list of TabsData Series (for on_batch) or TabsData supported scalars (for on_element) with the same length as specified in the output schema.
  5. If overriding the on_batch method, the return type must be a list of TabsData Series. If overriding the on_element method, the return type must be a list of supported TabsData scalar values. For both cases, the number of elements in the returned lists must match the number of elements in the output_columns list provided to the UDF constructor.

Using UDFs:

  1. Instantiate a function created as above.
  2. Pass it to TableFrame method udf().
  3. Optionally use :meth:UDF.output_columns to override output column names or data types after instantiation.

on_element
def on_element(values: list[Any]) -> list[Any]

Creating UDFs:

  1. Subclass :class:tabsdata.tableframe.udf.function.UDF.
  2. Implement __init__ to call super().__init__(output_columns) where output_columns is a tuple or list of tuples (name, data type) specifying the UDF default output schema (column names and data types). Each tuple must contain a column name (string) and a data type (DataType).
  3. Override exactly one of on_batch or on_element, to implement the UDF function logic.
  4. Return a list of TabsData Series (for on_batch) or TabsData supported scalars (for on_element) with the same length as specified in the output schema.
  5. If overriding the on_batch method, the return type must be a list of TabsData Series. If overriding the on_element method, the return type must be a list of supported TabsData scalar values. For both cases, the number of elements in the returned lists must match the number of elements in the output_columns list provided to the UDF constructor.

Using UDFs:

  1. Instantiate a function created as above.
  2. Pass it to TableFrame method udf().
  3. Optionally use :meth:UDF.output_columns to override output column names or data types after instantiation.

with_columns
def with_columns(
output_columns: tuple[str | None, DataTypeClass | DataType | NoneType] | list[tuple[str | None, DataTypeClass | DataType | NoneType]] | dict[int, tuple[str | None, DataTypeClass | DataType | NoneType]],
) -> UDF