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.__abs__()

Absolute of a numeric expression (abs(expr))

daft.expressions.Expression.__add__(other)

Adds two numeric expressions or concatenates two string 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.__truediv__(other)

True divides two numeric expressions (e1 / e2)

daft.expressions.Expression.__mod__(other)

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

Logical#

Operations on logical expressions (True/False booleans)

daft.expressions.Expression.__invert__()

Inverts a boolean expression (~e)

daft.expressions.Expression.__and__(other)

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

daft.expressions.Expression.__or__(other)

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

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

Conditionally choose values between two expressions using the current boolean 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)

Floats#

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

Example: e1.float.is_nan()

daft.expressions.Expression.float

Access methods that work on columns of floats

daft.expressions.expressions.ExpressionFloatNamespace.is_nan()

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

Strings#

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

Example: e1.str.concat(e2)

daft.expressions.Expression.str

Access methods that work on columns of strings

daft.expressions.expressions.ExpressionStringNamespace.concat(other)

Concatenates two string expressions together

daft.expressions.expressions.ExpressionStringNamespace.contains(substr)

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

daft.expressions.expressions.ExpressionStringNamespace.endswith(suffix)

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

daft.expressions.expressions.ExpressionStringNamespace.startswith(prefix)

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

daft.expressions.expressions.ExpressionStringNamespace.length()

Retrieves the length for a UTF-8 string column

Dates#

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

Example: e.dt.day()

daft.expressions.Expression.dt

Access methods that work on columns of datetimes

daft.expressions.expressions.ExpressionDatetimeNamespace.day

Retrieves the day for a datetime column

daft.expressions.expressions.ExpressionDatetimeNamespace.month

Retrieves the month for a datetime column

daft.expressions.expressions.ExpressionDatetimeNamespace.year

Retrieves the year for a datetime column

daft.expressions.expressions.ExpressionDatetimeNamespace.day_of_week

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

daft.expressions.expressions.ExpressionDatetimeNamespace.date

Retrieves the date for a datetime column

URLs#

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

Example: e.url.download()

daft.expressions.Expression.url

Access methods that work on columns of URLs

daft.expressions.expressions.ExpressionUrlNamespace.download

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

Images#

Operations on images, accessible through the Expression.image method accessor:

Example: e.image.resize()

daft.expressions.Expression.image

Access methods that work on columns of images

daft.expressions.expressions.ExpressionImageNamespace.resize

Resize image into the provided width and height.

daft.expressions.expressions.ExpressionImageNamespace.decode

Decodes the binary data in this column into images.

daft.expressions.expressions.ExpressionImageNamespace.encode

Encode an image column as the provided image file format, returning a binary column of encoded bytes.

Nested#

Operations on nested types (such as List and FixedSizeList), accessible through the Expression.list method accessor.

Example: e1.list.join(e2)

daft.expressions.expressions.ExpressionListNamespace.join(...)

Joins every element of a list using the specified string delimiter

daft.expressions.expressions.ExpressionListNamespace.lengths()

Gets the length of each list

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 the given datatype if possible

Running Python Functions#

daft.expressions.Expression.apply

Apply a function on each value in a given expression