Expr.cast
methodView source ↗
def cast(
dtype: td_DataType | type[Any],
strict: bool = True,
wrap_numerical: bool = False,
) -> Expr
Categories: type_casting
Cast a value to d different type.
Parameters
parameter
dtypeThe data type to cast to.
parameter
strictIf false, invalid casts produce null's; if true, an excetion is raised.
parameter
wrap_numericalIf true, overflowing numbers ara handled; if false, an excetion is raised.
Examples
>>> import tabsdata as td
>>> import polars as pl
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").cast(td.Float64)).alias("cast")
>>>
┌──────┬──────┐
│ val ┆ cast │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞══════╪══════╡
│ 1 ┆ 1.0 │
│ 15 ┆ 15.0 │
│ 18 ┆ 18.0 │
│ 60 ┆ 60.0 │
│ 60 ┆ 60.0 │
│ 75 ┆ 75.0 │
│ null ┆ null │
└──────┴──────┘