polars.Expr.to_physical
-
Cast to physical representation of the logical dtype.
-
polars.datatypes.Date()->polars.datatypes.Int32() -
polars.datatypes.Datetime()->polars.datatypes.Int64() -
polars.datatypes.Time()->polars.datatypes.Int64() -
polars.datatypes.Duration()->polars.datatypes.Int64() -
polars.datatypes.Categorical()->polars.datatypes.UInt32() -
List(inner)->List(physical of inner) -
Array(inner)->Struct(physical of inner) -
Struct(fields)->Array(physical of fields)
Other data types will be left unchanged.
Warning
The physical representations are an implementation detail and not guaranteed to be stable.
Examples
Replicating the pandas pd.factorize function.
>>> pl.DataFrame({"vals": ["a", "x", None, "a"]}).with_columns( ... pl.col("vals").cast(pl.Categorical), ... pl.col("vals") ... .cast(pl.Categorical) ... .to_physical() ... .alias("vals_physical"), ... ) shape: (4, 2) ┌──────┬───────────────┐ │ vals ┆ vals_physical │ │ --- ┆ --- │ │ cat ┆ u32 │ ╞══════╪═══════════════╡ │ a ┆ 0 │ │ x ┆ 1 │ │ null ┆ null │ │ a ┆ 0 │ └──────┴───────────────┘ -
Expr.to_physical() → Expr
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.to_physical.html