Expressions#

daft.expressions.Expression

Expression Constructors#

daft.DataFrame.__getitem__

Gets a column from the DataFrame as an Expression (df["mycol"])

daft.expressions.col

Creates an Expression referring to the column with the provided name

daft.expressions.lit

Creates an Expression representing a column with every value set to the provided value

Operators#

Numeric#

Operations on numbers (floats and integers)

daft.expressions.Expression.__neg__()

Negates a numeric expression (-expr)

daft.expressions.Expression.__pos__()

Positive of a numeric expression (+expr)

daft.expressions.Expression.__abs__()

Absolute of a numeric expression (abs(expr))

daft.expressions.Expression.__add__(other)

Adds two numeric expressions (e1 + e2)

daft.expressions.Expression.__sub__(other)

Subtracts two numeric expressions (e1 - e2)

daft.expressions.Expression.__mul__(other)

Multiplies two numeric expressions (e1 * e2)

daft.expressions.Expression.__floordiv__(other)

Floor divides two numeric expressions (e1 // e2)

daft.expressions.Expression.__truediv__(other)

True divides two numeric expressions (e1 / e2)

daft.expressions.Expression.__pow__(other)

Takes the power of two numeric expressions (e1 ** e2)

daft.expressions.Expression.__mod__(other)

Takes the mod of two numeric expressions (e1 % e2)

daft.expressions.Expression.is_nan()

Checks if values are NaN (a special float value indicating not-a-number)

Logical#

Operations on logical expressions (True/False booleans)

daft.expressions.Expression.__invert__()

Inverts a logical expression (~e)

daft.expressions.Expression.__and__(other)

Takes the logical AND of two expressions (e1 & e2)

daft.expressions.Expression.__or__(other)

Takes the logical OR of two expressions (e1 | e2)

daft.expressions.Expression.if_else(if_true, ...)

Conditionally choose values between two expressions using the current LOGICAL expression as a condition

Comparisons#

Comparing expressions and values, returning a logical expression

daft.expressions.Expression.__lt__(other)

Compares if an expression is less than another (e1 < e2)

daft.expressions.Expression.__le__(other)

Compares if an expression is less than or equal to another (e1 <= e2)

daft.expressions.Expression.__eq__(other)

Compares if an expression is equal to another (e1 == e2)

daft.expressions.Expression.__ne__(other)

Compares if an expression is not equal to another (e1 != e2)

daft.expressions.Expression.__gt__(other)

Compares if an expression is greater than another (e1 > e2)

daft.expressions.Expression.__ge__(other)

Compares if an expression is greater than or equal to another (e1 >= e2)

daft.expressions.Expression.is_null()

Checks if values in the Expression are Null (a special value indicating missing data)

Strings#

Operations on strings, accessible through the Expression.str method accessor.

Example: e1.str.concat(e2)

daft.expressions.StringMethodAccessor.concat(other)

Concatenates two string expressions together

daft.expressions.StringMethodAccessor.contains(pattern)

Checks whether each string contains the given pattern in a string column

daft.expressions.StringMethodAccessor.endswith(pattern)

Checks whether each string ends with the given pattern in a string column

daft.expressions.StringMethodAccessor.startswith(pattern)

Checks whether each string starts with the given pattern in a string column

daft.expressions.StringMethodAccessor.length()

Retrieves the length for of a UTF-8 string column

Dates#

Operations on datetimes, accessible through the Expression.dt method accessor:

Example: e.dt.day()

daft.expressions.DatetimeMethodAccessor.day

Retrieves the day for a datetime column

daft.expressions.DatetimeMethodAccessor.month

Retrieves the month for a datetime column

daft.expressions.DatetimeMethodAccessor.year

Retrieves the year for a datetime column

daft.expressions.DatetimeMethodAccessor.day_of_week

Retrieves the day of the week for a datetime column, starting at 0 for Monday and ending at 6 for Sunday

URLs#

Operations on URLs, accessible through the Expression.url method accessor:

Example: e.url.download()

daft.expressions.UrlMethodAccessor.download

Treats each string as a URL, and downloads the bytes contents as a bytes column

Changing Column Names/Types#

daft.expressions.Expression.alias

Gives the expression a new name, which is its column's name in the DataFrame schema and the name by which subsequent expressions can refer to the results of this expression.

daft.expressions.Expression.cast

Casts an expression to a given type

Running Python Functions#

daft.expressions.Expression.as_py

Treats every value on the given expression as an object of the specified type.

daft.expressions.Expression.apply

Apply a function on a given expression