daft.expressions.Expression.apply
daft.expressions.Expression.apply#
- Expression.apply(func: Callable, return_dtype: daft.datatype.DataType) daft.expressions.expressions.Expression [source]#
Apply a function on each value in a given expression
Note
This is just syntactic sugar on top of a UDF and is convenient to use when your function only operates on a single column, and does not benefit from executing on batches. For either of those other use-cases, use a UDF instead.
Example
>>> def f(x_val: str) -> int: >>> return int(x_val) if x_val.isnumeric() else 0 >>> >>> col("x").apply(f, return_dtype=DataType.int64())
- Parameters
func – Function to run per value of the expression
return_dtype – Return datatype of the function that was ran
- Returns
New expression after having run the function on the expression
- Return type