Shrink numeric columns to the minimal required datatype
Description
Shrink to the dtype needed to fit the extrema of this Series. This can be used to reduce memory pressure.
Usage
<Expr>$shrink_dtype()
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(a = c(-112, 2, 112))$cast(pl$Int64)
df$with_columns(
shrunk = pl$col("a")$shrink_dtype()
)
#> shape: (3, 2)
#> ┌──────┬────────┐
#> │ a ┆ shrunk │
#> │ --- ┆ --- │
#> │ i64 ┆ i8 │
#> ╞══════╪════════╡
#> │ -112 ┆ -112 │
#> │ 2 ┆ 2 │
#> │ 112 ┆ 112 │
#> └──────┴────────┘