polars.datatypes.Enum#

class polars.datatypes.Enum(categories: Series | Iterable[str] | type[enum.Enum])[source]#

A fixed categorical encoding of a unique set of strings.

Warning

This functionality is considered unstable. It is a work-in-progress feature and may not always work as expected. It may be changed at any point without it being considered a breaking change.

Parameters:
categories

The categories in the dataset; must be a unique set of strings, or an existing Python string-valued enum.

Examples

Explicitly define enumeration categories:

>>> pl.Enum(["north", "south", "east", "west"])
Enum(categories=['north', 'south', 'east', 'west'])

Initialise from an existing Python enumeration:

>>> from http import HTTPMethod
>>> pl.Enum(HTTPMethod)
Enum(categories=['CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE'])
__init__(categories: Series | Iterable[str] | type[enum.Enum]) None[source]#

Methods

__init__(categories)

base_type()

Return this DataType's fundamental/root type class.

from_python(py_type)

Return the Polars data type corresponding to a given Python type.

is_(other)

Check if this DataType is the same as another DataType.

is_decimal()

Check whether the data type is a decimal type.

is_float()

Check whether the data type is a floating point type.

is_integer()

Check whether the data type is an integer type.

is_nested()

Check whether the data type is a nested type.

is_numeric()

Check whether the data type is a numeric type.

is_signed_integer()

Check whether the data type is a signed integer type.

is_temporal()

Check whether the data type is a temporal type.

is_unsigned_integer()

Check whether the data type is an unsigned integer type.

to_python()

Return the Python type corresponding to this Polars data type.

union(other)

Union of two Enums.

Attributes

categories