Skip to content

Polars DataType class (polars_dtype)

Description

Polars supports a variety of data types that fall broadly under the following categories:

  • Numeric data types: signed integers, unsigned integers, floating point numbers, and decimals.
  • Nested data types: lists, structs, and arrays.
  • Temporal: dates, datetimes, times, and time deltas.
  • Miscellaneous: strings, binary data, Booleans, categoricals, and enums.

All types support missing values represented by the special value null. This is not to be conflated with the special value NaN in floating number data types; see the section about floating point numbers for more information.

Usage

pl__Decimal(precision = NULL, scale = 0L)

pl__Datetime(time_unit = c("us", "ns", "ms"), time_zone = NULL)

pl__Duration(time_unit = c("us", "ns", "ms"))

pl__Categorical(ordering = c("physical", "lexical"))

pl__Enum(categories)

pl__Array(inner, shape)

pl__List(inner)

pl__Struct(...)

Arguments

precision Single integer or NULL (default), maximum number of digits in each number. If NULL, the precision is inferred.
scale Single integer or NULL. Number of digits to the right of the decimal point in each number. The default is 0.
time_unit One of “us” (default, microseconds), “ns” (nanoseconds) or “ms”(milliseconds). Representing the unit of time.
time_zone A string or NULL (default). Representing the timezone.
ordering One of “physical” (default) or “lexical”. Ordering by order of appearance (“physical”) or string value (“lexical”).
categories A character vector. Should not contain NA values and all values should be unique.
inner A polars data type object.
shape A integer-ish vector, representing the shape of the Array.
\<dynamic-dots\> Name-value pairs of polars data type. Each pair represents a field of the Struct.

Details

Full data types table

Type(s) Details
Boolean Boolean type that is bit packed efficiently.
Int8, Int16, Int32, Int64 Varying-precision signed integer types.
UInt8, UInt16, UInt32, UInt64 Varying-precision unsigned integer types.
Float32, Float64 Varying-precision signed floating point numbers.
Decimal [Experimental] Decimal 128-bit type with optional precision and non-negative scale.
String Variable length UTF-8 encoded string data, typically Human-readable.
Binary Stores arbitrary, varying length raw binary data.
Date Represents a calendar date.
Time Represents a time of day.
Datetime Represents a calendar date and time of day.
Duration Represents a time duration.
Array Arrays with a known, fixed shape per series; akin to numpy arrays.
List Homogeneous 1D container with variable length.
Categorical Efficient encoding of string data where the categories are inferred at runtime.
Enum [Experimental] Efficient ordered encoding of a set of predetermined string categories.
Struct Composite product type that can store multiple fields.
Null Represents null values.

Examples

library("polars")

pl$Int8
#> Int8
pl$Int16
#> Int16
pl$Int32
#> Int32
pl$Int64
#> Int64
pl$UInt8
#> UInt8
pl$UInt16
#> UInt16
pl$UInt32
#> UInt32
pl$UInt64
#> UInt64
pl$Float32
#> Float32
pl$Float64
#> Float64
pl$Decimal(scale = 2)
#> Decimal(precision=NULL, scale=2)
pl$String
#> String
pl$Binary
#> Binary
pl$Date
#> Date
pl$Time
#> Time
pl$Datetime()
#> Datetime(time_unit='us', time_zone=NULL)
pl$Duration()
#> Duration(time_unit='us')
pl$Array(pl$Int32, c(2, 3))
#> Array(Int32, shape=c(2, 3))
pl$List(pl$Int32)
#> List(Int32)
pl$Categorical()
#> Categorical(ordering='physical')
pl$Enum(c("a", "b", "c"))
#> Enum(categories=c('a', 'b', 'c'))
pl$Struct(a = pl$Int32, b = pl$String)
#> Struct(`a`=Int32, `b`=String)
pl$Null
#> Null