ray.data.expressions.lit#
- ray.data.expressions.lit(value: Any) LiteralExpr [source]#
Create a literal expression from a constant value.
This creates an expression that represents a constant scalar value. The value will be broadcast to all rows when the expression is evaluated.
- Parameters:
value – The constant value to represent. Can be any Python object (int, float, str, bool, etc.)
- Returns:
A LiteralExpr containing the specified value
Example
>>> from ray.data.expressions import col, lit >>> # Create literals of different types >>> five = lit(5) >>> pi = lit(3.14159) >>> name = lit("Alice") >>> flag = lit(True) >>> >>> # Use in expressions >>> expr = col("age") + lit(1) # Add 1 to age column >>> >>> # Use with Dataset.with_columns() >>> import ray >>> ds = ray.data.from_items([{"age": 25}, {"age": 30}]) >>> ds = ds.with_columns({"age_plus_one": col("age") + lit(1)})
PublicAPI (beta): This API is in beta and may change before becoming stable.