polars.Expr.reinterpret#
- Expr.reinterpret( ) Expr[source]#
Reinterpret the underlying bits as a signed/unsigned integer, float or decimal.
This operation is only allowed between numeric types of the same size. To convert between types of different sizes, use
cast()instead.A
Decimalcan also be reinterpreted to and fromInt128, its unscaled integer representation:1.23asDecimal(5, 2)becomes123. Reinterpreting anInt128raises if the value doesn’t fit the precision of the targetDecimal.Exactly one of
signedordtypemust be specified.- Parameters:
- signed
If True, reinterpret as signed integer. Otherwise, reinterpret as unsigned integer.
- dtype
DataType to reinterpret to.
Examples
>>> s = pl.Series("a", [1, 1, 2], dtype=pl.UInt64) >>> df = pl.DataFrame([s]) >>> df.select( ... [ ... pl.col("a").reinterpret(dtype=pl.Int64).alias("reinterpreted"), ... pl.col("a").alias("original"), ... ] ... ) shape: (3, 2) ┌───────────────┬──────────┐ │ reinterpreted ┆ original │ │ --- ┆ --- │ │ i64 ┆ u64 │ ╞═══════════════╪══════════╡ │ 1 ┆ 1 │ │ 1 ┆ 1 │ │ 2 ┆ 2 │ └───────────────┴──────────┘