polars.Expr.reinterpret
-
Reinterpret the underlying bits as a signed/unsigned integer or float.
This operation is only allowed for numeric types of the same size. For lower bits numbers, you can safely use the cast operation.
Either
signedordtypecan be specified. Defaults tosigned=Trueotherwise.- 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 │ └───────────────┴──────────┘
Expr.reinterpret(
*,
signed: bool | None = None,
dtype: PolarsDataType | None = None,
) → Expr
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.reinterpret.html