tabsdata.tableframe.udf.function
UDF | |
UDF.columns | |
UDF.on_batch | Creating UDFs: 1. |
UDF.on_element | Creating UDFs: 1. |
UDF.with_columns |
UDF
classView source ↗
class UDF(
output_columns: list[tuple[str, DataTypeClass | DataType]] | tuple[str, DataTypeClass | DataType],
)
Bases: ABC
method
View source ↗on_batchdef on_batch(series: list[Series]) -> list[Series]
Creating UDFs:
- Subclass :class:
tabsdata.tableframe.udf.function.UDF. - Implement
__init__to callsuper().__init__(output_columns)whereoutput_columnsis 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). - Override exactly one of
on_batchoron_element, to implement the UDF function logic. - Return a list of TabsData Series (for
on_batch) or TabsData supported scalars (foron_element) with the same length as specified in the output schema. - If overriding the
on_batchmethod, the return type must be a list of TabsData Series. If overriding theon_elementmethod, 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:
- Instantiate a function created as above.
- Pass it to TableFrame method udf().
- Optionally use :meth:
UDF.output_columnsto override output column names or data types after instantiation.
method
View source ↗on_elementdef on_element(values: list[Any]) -> list[Any]
Creating UDFs:
- Subclass :class:
tabsdata.tableframe.udf.function.UDF. - Implement
__init__to callsuper().__init__(output_columns)whereoutput_columnsis 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). - Override exactly one of
on_batchoron_element, to implement the UDF function logic. - Return a list of TabsData Series (for
on_batch) or TabsData supported scalars (foron_element) with the same length as specified in the output schema. - If overriding the
on_batchmethod, the return type must be a list of TabsData Series. If overriding theon_elementmethod, 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:
- Instantiate a function created as above.
- Pass it to TableFrame method udf().
- Optionally use :meth:
UDF.output_columnsto override output column names or data types after instantiation.
method
View source ↗with_columnsdef 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