property Model.valid_dtypes: dict[str, List[Union[Type[polars.datatypes.DataType], polars.datatypes.DataType, polars.datatypes.List]]]

Return a list of polars dtypes which Patito considers valid for each field.

The first item of each list is the default dtype chosen by Patito.

Return type

dict[str, List[Union[Type[DataType], DataType, List]]]


A dictionary mapping each column string name to a list of valid dtypes.


NotImplementedError – If one or more model fields are annotated with types not compatible with polars.


>>> from pprint import pprint
>>> import patito as pt
>>> class MyModel(pt.Model):
...     bool_column: bool
...     str_column: str
...     int_column: int
...     float_column: float
>>> pprint(MyModel.valid_dtypes)
{'bool_column': [<class 'polars.datatypes.Boolean'>],
 'float_column': [<class 'polars.datatypes.Float64'>,
                  <class 'polars.datatypes.Float32'>],
 'int_column': [<class 'polars.datatypes.Int64'>,
                <class 'polars.datatypes.Int32'>,
                <class 'polars.datatypes.Int16'>,
                <class 'polars.datatypes.Int8'>,
                <class 'polars.datatypes.UInt64'>,
                <class 'polars.datatypes.UInt32'>,
                <class 'polars.datatypes.UInt16'>,
                <class 'polars.datatypes.UInt8'>],
 'str_column': [<class 'polars.datatypes.Utf8'>]}