Skip to main content
Version: 1.9.1

tabsdata.tableframe.udf.function

UDF
UDF.columns
UDF.on_batchCreating UDFs:
UDF.on_elementCreating UDFs:
UDF.with_columns
UDFListAbstract base class for UDFs that use list-style parameter passing.
UDFList.columns
UDFList.on_batchCreating UDFs:
UDFList.on_elementCreating UDFs:
UDFList.with_columns
UDFUnpackedAbstract base class for UDFs that use unpacked-style parameter passing.
UDFUnpacked.columns
UDFUnpacked.on_batchCreating UDFs:
UDFUnpacked.on_elementCreating UDFs:
UDFUnpacked.with_columns

UDF

class UDF(
output_columns: list[tuple[str, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64]] | tuple[str, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64],
)

Bases: ABC

property
signatureLiteral['list', 'unpacked']

Defines how parameters are passed to on_batch and on_element methods.

Returns: "list": Parameters are passed as a single list (default). "unpacked": Each parameter is passed as a separate argument.

Override this property in your UDF subclass to change the parameter style.

columns
def columns(
,
) -> list[tuple[str, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64]]

on_batch
def on_batch(*args) -> 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.
  4. By default, on_batch receives a list of series. Override the signature property to return "unpacked" to receive each series as a separate argument instead.

on_element
def on_element(*args) -> 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.
  4. By default, on_element receives a list of values. Override the signature property to return "unpacked" to receive each value as a separate argument instead.

with_columns
def with_columns(
output_columns: tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType] | list[tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType]] | dict[int, tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType]],
) -> UDF

UDFList

class UDFList(output_columns)

Bases: UDF, ABC

Abstract base class for UDFs that use list-style parameter passing.

When subclassing UDFList, implement on_batch or on_element with list signature:

  • on_batch(self, series: list[Series]) -> list[Series]
  • on_element(self, values: list[Any]) -> list[Any]

property
signatureLiteral['list', 'unpacked']

Defines how parameters are passed to on_batch and on_element methods.

Returns: "list": Parameters are passed as a single list (default). "unpacked": Each parameter is passed as a separate argument.

Override this property in your UDF subclass to change the parameter style.

columns
def columns(
,
) -> list[tuple[str, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64]]

on_batch
def on_batch(*args) -> 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.
  4. By default, on_batch receives a list of series. Override the signature property to return "unpacked" to receive each series as a separate argument instead.

on_element
def on_element(*args) -> 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.
  4. By default, on_element receives a list of values. Override the signature property to return "unpacked" to receive each value as a separate argument instead.

with_columns
def with_columns(
output_columns: tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType] | list[tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType]] | dict[int, tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType]],
) -> UDF

UDFUnpacked

class UDFUnpacked(output_columns)

Bases: UDF, ABC

Abstract base class for UDFs that use unpacked-style parameter passing.

When subclassing UDFUnpacked, implement on_batch or on_element with unpacked signature:

  • on_batch(self, col1: Series, col2: Series, ...) -> list[Series]
  • on_element(self, val1: Any, val2: Any, ...) -> list[Any]

property
signatureLiteral['list', 'unpacked']

Defines how parameters are passed to on_batch and on_element methods.

Returns: "list": Parameters are passed as a single list (default). "unpacked": Each parameter is passed as a separate argument.

Override this property in your UDF subclass to change the parameter style.

columns
def columns(
,
) -> list[tuple[str, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64]]

on_batch
def on_batch(*args) -> 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.
  4. By default, on_batch receives a list of series. Override the signature property to return "unpacked" to receive each series as a separate argument instead.

on_element
def on_element(*args) -> 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.
  4. By default, on_element receives a list of values. Override the signature property to return "unpacked" to receive each value as a separate argument instead.

with_columns
def with_columns(
output_columns: tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType] | list[tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType]] | dict[int, tuple[str | None, Boolean | Categorical | Date | Datetime | Decimal | Duration | Enum | Float16 | Float32 | Float64 | Int8 | Int16 | Int64 | Int32 | Int128 | Null | String | Time | UInt8 | UInt16 | UInt32 | UInt64 | NoneType]],
) -> UDF