Skip to content

Transformation Functions API#

udf #

udf(
    return_type: list[type] | type,
    drop: str | list[str] | None = None,
    mode: Literal[
        "default", "python", "pandas"
    ] = "default",
) -> HopsworksUdf

Create an User Defined Function that can be and used within the Hopsworks Feature Store to create transformation functions.

Hopsworks UDF's are user defined functions that executes as 'pandas_udf' when executing in spark engine and as pandas functions in the python engine. The pandas udf/pandas functions gets as inputs pandas Series's and can provide as output a pandas Series or a pandas DataFrame. A Hopsworks udf is defined using the hopsworks_udf decorator. The outputs of the defined UDF must be mentioned in the decorator as a list of python types.

Example
from hopsworks import udf

@udf(float)
def add_one(data1):
    return data1 + 1
PARAMETER DESCRIPTION
return_type

The output types of the defined UDF.

TYPE: list[type] | type

drop

The features to be dropped after application of transformation functions.

TYPE: str | list[str] | None DEFAULT: None

mode

The exection mode of the UDF.

TYPE: Literal['default', 'python', 'pandas'] DEFAULT: 'default'

RETURNS DESCRIPTION
HopsworksUdf

The metadata object for hopsworks UDF's.

RAISES DESCRIPTION
hopsworks.client.exceptions.FeatureStoreException

If unable to create UDF.