snowflake.snowpark.functions.vectorized¶
- snowflake.snowpark.functions.vectorized(input: type, max_batch_size: Optional[int] = None) Callable [source]¶
Marks a function or UDTF method as vectorized for pandas input. This decorator is a no-op for local invocation. When combined with
udf()
, this will make the function behave as a vectorized UDF usingpandas_udf()
.- Parameters:
input – The type of the input to the function. Must be either
pandas.Series
orpandas.DataFrame
.max_batch_size – The maximum batch size to use for the function. If not provided, the default batch size will be used.
- Returns:
A decorator that marks the function as vectorized.
Example:
>>> import pandas as pd >>> from snowflake.snowpark.functions import udf, vectorized >>> from snowflake.snowpark.types import IntegerType >>> @udf(return_type=IntegerType(), input_types=[IntegerType(), IntegerType()]) ... @vectorized(input=pd.DataFrame) ... def add_one_to_inputs(df): ... return df[0] + df[1] + 1 >>> df = session.create_dataframe([[1, 2], [3, 4]], schema=["a", "b"]) >>> df.select(add_one_to_inputs("a", "b").alias("result")).collect() [Row(RESULT=4), Row(RESULT=8)]
See also