polars.datatypes.Categorical#

class polars.datatypes.Categorical(
categories: Categories | str | None = None,
*,
ordering: CategoricalOrdering | None = None,
)[source]#

A categorical encoding of a set of strings.

Parameters:
categories

The categories used for this type; must be a Categories instance, or a string which is interpreted as the name of a Categories. If not provided, the global categories (pl.Categories()) are used.

For legacy reasons if the string is either "physical" or "lexical", it is ignored and a warning is issued. If you wish to use a Categories named "physical" or "lexical", please pass it using Categories explicitly.

ordering{‘lexical’, ‘physical’}

This used to specify how this type was ordered, but now does nothing.

Deprecated since version 1.32.0: Parameter is now ignored. Always behaves as if 'lexical' was passed.

See also

Categories
__init__(
categories: Categories | str | None = None,
*,
ordering: CategoricalOrdering | None = None,
) None[source]#

Methods

__init__([categories, ordering])

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_object()

Check whether the data type is an object 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_dtype_expr()

Return a DataTypeExpr with a static DataType.

to_python()

Return the Python type corresponding to this Polars data type.

Attributes

ordering

categories