ray.data.expressions.Expr#

class ray.data.expressions.Expr(data_type: DataType)[source]#

Bases: ABC

Base class for all expression nodes.

This is the abstract base class that all expression types inherit from. It provides operator overloads for building complex expressions using standard Python operators.

Expressions form a tree structure where each node represents an operation or value. The tree can be evaluated against data batches to compute results.

Example

>>> from ray.data.expressions import col, lit
>>> # Create an expression tree: (col("x") + 5) * col("y")
>>> expr = (col("x") + lit(5)) * col("y")
>>> # This creates a BinaryExpr with operation=MUL
>>> # left=BinaryExpr(op=ADD, left=ColumnExpr("x"), right=LiteralExpr(5))
>>> # right=ColumnExpr("y")

Note

This class should not be instantiated directly. Use the concrete subclasses like ColumnExpr, LiteralExpr, etc.

DeveloperAPI: This API may change across minor Ray releases.

Methods

abs

Compute the absolute value of the expression.

alias

Rename the expression.

ceil

Round values up to the nearest integer.

exp

Compute the natural exponential of the expression.

floor

Round values down to the nearest integer.

is_in

Check if the expression value is in a list of values.

is_not_null

Check if the expression value is not null.

is_null

Check if the expression value is null.

ln

Compute the natural logarithm of the expression.

log10

Compute the base-10 logarithm of the expression.

log2

Compute the base-2 logarithm of the expression.

negate

Compute the negation of the expression.

not_in

Check if the expression value is not in a list of values.

power

Raise the expression to the given power.

round

Round values to the nearest integer using PyArrow semantics.

sign

Compute the sign of the expression.

structurally_equals

Compare two expression ASTs for structural equality.

to_pyarrow

Convert this Ray Data expression to a PyArrow compute expression.

trunc

Truncate fractional values toward zero.

Attributes

dt

Access datetime operations for this expression.

list

Access list operations for this expression.

name

Get the name associated with this expression.

str

Access string operations for this expression.

struct

Access struct operations for this expression.

data_type