Skip to content

Get the size of binary values in the given unit

Description

Get the size of binary values in the given unit

Usage

<Expr>$bin$size(unit = c("b", "kb", "mb", "gb", "tb"))

Arguments

unit Scale the returned size to the given unit. Can be “b”, “kb”, “mb”, “gb”, “tb”.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  name = c("black", "yellow", "blue"),
  code_hex = as_polars_series(c("000000", "ffff00", "0000ff"))$cast(pl$Binary)
)

df$with_columns(
  n_bytes = pl$col("code_hex")$bin$size(),
  n_kilobytes = pl$col("code_hex")$bin$size("kb")
)
#> shape: (3, 4)
#> ┌────────┬───────────┬─────────┬─────────────┐
#> │ name   ┆ code_hex  ┆ n_bytes ┆ n_kilobytes │
#> │ ---    ┆ ---       ┆ ---     ┆ ---         │
#> │ str    ┆ binary    ┆ u32     ┆ f64         │
#> ╞════════╪═══════════╪═════════╪═════════════╡
#> │ black  ┆ b"000000" ┆ 6       ┆ 0.005859    │
#> │ yellow ┆ b"ffff00" ┆ 6       ┆ 0.005859    │
#> │ blue   ┆ b"0000ff" ┆ 6       ┆ 0.005859    │
#> └────────┴───────────┴─────────┴─────────────┘