Skip to content

Get the DataType wrapped in an array

Source code

Description

[Experimental] Get the DataType wrapped in an array.

Usage

<DataTypeExpr>$wrap_in_array(..., width)

Arguments

These dots are for future extensions and must be empty.
width Width of the array.

Value

A polars datatype expression. This is not the same as a polars expression.

Examples

library("polars")

df <- pl$DataFrame(
  a = 1L,
  b = list("a"),
  c = data.frame(x = 1, y = 2)
)

df$select(
  a_wrapped = pl$dtype_of("a")$wrap_in_array(width = 1)$display(),
  b_wrapped = pl$dtype_of("b")$wrap_in_array(width = 1)$display(),
  c_wrapped = pl$dtype_of("c")$wrap_in_array(width = 1)$display()
)
#> shape: (1, 3)
#> ┌───────────────┬─────────────────────┬─────────────────────┐
#> │ a_wrapped     ┆ b_wrapped           ┆ c_wrapped           │
#> │ ---           ┆ ---                 ┆ ---                 │
#> │ str           ┆ str                 ┆ str                 │
#> ╞═══════════════╪═════════════════════╪═════════════════════╡
#> │ array[i32, 1] ┆ array[list[str], 1] ┆ array[struct[2], 1] │
#> └───────────────┴─────────────────────┴─────────────────────┘