Dtypes¶
dtypes
¶
Dtype families used to decide which primitives apply to which columns.
Matching is done on narwhals dtypes alone. There are no logical types and no semantic tags: the cost is losing the distinction between an integer that is a quantity and one that is a category; the benefit is identical behaviour on every backend with no extra dependencies.
DtypeFamily
¶
Bases: Enum
A group of narwhals dtypes that a primitive can accept.
STRING and CATEGORICAL are disjoint: a String column is not a
Categorical or Enum one, even though all three hold text-like
values. That distinction is deliberate -- it is what
:class:~tusk.exceptions.CategoricalDtypeWarning reports -- and it is why
both families exist rather than one wider one.
matches
¶
Report whether a dtype belongs to a family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
DType
|
The narwhals dtype to test. |
required |
family
|
DtypeFamily
|
The family to test membership of. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the dtype belongs to the family. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If family is not a recognized DtypeFamily member. |