ray.data.expressions.UDFExpr#
- class ray.data.expressions.UDFExpr(data_type: DataType, fn: Callable[..., BatchColumn], args: List[Expr], kwargs: Dict[str, Expr])[source]#
Bases:
ExprExpression that represents a user-defined function call.
This expression type wraps a UDF with schema inference capabilities, allowing UDFs to be used seamlessly within the expression system.
UDFs operate on batches of data, where each column argument is passed as a PyArrow Array containing multiple values from that column across the batch.
- Parameters:
fn – The user-defined function to call. For callable classes, this is an _CallableClassUDF instance that handles lazy instantiation internally.
args – List of argument expressions (positional arguments)
kwargs – Dictionary of keyword argument expressions
Example
>>> from ray.data.expressions import col, udf >>> import pyarrow as pa >>> import pyarrow.compute as pc >>> from ray.data.datatype import DataType >>> >>> @udf(return_dtype=DataType.int32()) ... def add_one(x: pa.Array) -> pa.Array: ... return pc.add(x, 1) >>> >>> # Use in expressions >>> expr = add_one(col("value"))
>>> # Callable class example >>> @udf(return_dtype=DataType.int32()) ... class AddOffset: ... def __init__(self, offset=1): ... self.offset = offset ... def __call__(self, x: pa.Array) -> pa.Array: ... return pc.add(x, self.offset) >>> >>> # Use callable class >>> add_five = AddOffset(5) >>> expr = add_five(col("value"))
DeveloperAPI: This API may change across minor Ray releases.
Methods
Compute the absolute value of the expression.
Rename the expression.
Round values up to the nearest integer.
Compute the natural exponential of the expression.
Round values down to the nearest integer.
Check if the expression value is in a list of values.
Check if the expression value is not null.
Check if the expression value is null.
Compute the natural logarithm of the expression.
Compute the base-10 logarithm of the expression.
Compute the base-2 logarithm of the expression.
Compute the negation of the expression.
Check if the expression value is not in a list of values.
Raise the expression to the given power.
Round values to the nearest integer using PyArrow semantics.
Compute the sign of the expression.
Convert this Ray Data expression to a PyArrow compute expression.
Truncate fractional values toward zero.
Attributes
Return callable_class_spec if fn is an _CallableClassUDF, else None.
Access datetime operations for this expression.
Access list operations for this expression.
Get the name associated with this expression.
Access string operations for this expression.
Access struct operations for this expression.