Skip to main content
Version: 1.9.1

Expr.cast

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
dtype

The data type to cast to.

parameter
strict

If false, invalid casts produce null's; if true, an excetion is raised.

parameter
wrap_numerical

If 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 │
╞══════╪══════╡
11.0
1515.0
1818.0
6060.0
6060.0
7575.0
│ null ┆ null │
└──────┴──────┘