tabsdata.tableframe.expr.expr.Expr.cast#

Expr.cast(dtype: td_typing.TdDataType | type[Any], *, strict: bool = True, wrap_numerical: bool = False) Expr[source]#

Cast a value to d different type.

Parameters:
  • dtype – The data type to cast to.

  • strict – If false, invalid casts produce null’s; if true, an excetion is raised.

  • wrap_numerical – If true, overflowing numbers ara handled; if false, an excetion is raised.

Example:

>>> import tabsdata as td
>>> import polars as pl
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").cast(pl.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 │
└──────┴──────┘