ray.data.expressions.Expr.sign#

Expr.sign() UDFExpr[source]#

Compute the sign of the expression.

Returns:

A UDFExpr that returns -1 for negative values, 0 for zero, and 1 for positive values.

Example

>>> from ray.data.expressions import col
>>> import ray
>>> ds = ray.data.from_items([{"x": 5}, {"x": -3}, {"x": 0}])
>>> ds = ds.with_column("sign_x", col("x").sign())
>>> # Result: sign_x = [1, -1, 0]