patito.Model.examples
- classmethod Model.examples(data=None, columns=None)
Generate polars dataframe with dummy data for all unspecified columns.
This constructor accepts the same data format as polars.DataFrame.
- Parameters
data (
Union
[dict
,Iterable
,None
]) – Data to populate the dummy dataframe with. If given as an iterable of values, then column names must also be provided. If not provided at all, a dataframe with a single row populated with dummy data is provided.columns (
Optional
[Iterable
[str
]]) – Ignored ifdata
is provided as a dictionary. If data is provided as aniterable
, thencolumns
will be used as the column names in the resulting dataframe. Defaults to None.
- Return type
- Returns
A polars dataframe where all unspecified columns have been filled with dummy data which should pass model validation.
- Raises
TypeError – If one or more of the model fields are not mappable to polars column dtype equivalents.
Example
>>> from typing import Literal >>> import patito as pt
>>> class Product(pt.Model): ... product_id: int = pt.Field(unique=True) ... name: str ... temperature_zone: Literal["dry", "cold", "frozen"] ...
>>> Product.examples() shape: (1, 3) ┌──────────────┬──────────────────┬────────────┐ │ name ┆ temperature_zone ┆ product_id │ │ --- ┆ --- ┆ --- │ │ str ┆ cat ┆ i64 │ ╞══════════════╪══════════════════╪════════════╡ │ dummy_string ┆ dry ┆ 0 │ └──────────────┴──────────────────┴────────────┘
>>> Product.examples({"name": ["product A", "product B"]}) shape: (2, 3) ┌───────────┬──────────────────┬────────────┐ │ name ┆ temperature_zone ┆ product_id │ │ --- ┆ --- ┆ --- │ │ str ┆ cat ┆ i64 │ ╞═══════════╪══════════════════╪════════════╡ │ product A ┆ dry ┆ 0 │ ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ │ product B ┆ dry ┆ 1 │ └───────────┴──────────────────┴────────────┘