daft.expressions.Expression.cast
daft.expressions.Expression.cast#
- Expression.cast(to: type) daft.expressions.Expression [source]#
Casts an expression to a given type
Casting defaults to a set of “reasonable behaviors” for each
(from_type, to_type)
pair. For more fine-grained control, please consult each type’s method accessors or make a feature request for an accessor if none exists for your use-case.This method supports:
Casting of a PY type to a Primitive type (e.g. converting a PY[object] column of strings to STRING with
.cast(str)
) - this will coerce each Python object into the specified primitive type, and then convert the data to an optimized backend representation.Casting between Primitive types, with a set of reasonable default behavior for many type pairs
Example
>>> # [1.0, 2.5, None]: FLOAT -> [1, 2, None]: INTEGER >>> col("float").cast(int) >>> >>> # [Path("/tmp1"), Path("/tmp2"), Path("/tmp3")]: PY[Path] -> ["/tmp1", "/tmp1", "/tmp1"]: STRING >>> col("path_obj_col").cast(str)
- Returns
Expression with the specified new type
- Return type