Skip to content

expressions

Reusable Polars expressions and dtype predicates.

Functions:

is_numeric_dtype(dtype)

Integers, floats and decimals (not booleans).

is_temporal_dtype(dtype)

Dates and datetimes. Times and durations are not profiled as dates.

is_hashable_dtype(dtype)

Whether values can be counted (and used as keys of the value counts).

Nested values (lists, arrays, structs) come back to Python as lists and dicts, which cannot key a dict; like pandas, they are not counted.

is_orderable_dtype(dtype)

Whether distinct values can be sorted (for the extreme values tables).

parse_numeric(expr)

Strings as Float64; values that are not numbers become null.

Like pandas.to_numeric(errors="coerce"): surrounding whitespace is ignored, "nan" is a missing value and "inf" is infinity.

parse_datetime(expr)

Strings as naive Datetime("us"); values that are not dates become null.

Offsets (+02:00, Z) are converted to UTC.

parse_bool(expr, mapping)

Strings as booleans through a case-insensitive mapping.

estimated_size(expr, dtype, n=None)

An expression for the number of bytes a column takes in memory.

Computed from the data, so it works on a LazyFrame that is never materialised. Fixed-width types count their width, strings and binaries their bytes plus 8-byte offsets, lists their offsets plus their values, structs the sum of their fields, and every column one validity bit per row. Returns None for object columns.

Args: expr: the column. dtype: its dtype. n: its number of values (default: the frame's length).