patito.Model.DataFrame
- Model.DataFrame(data=None, columns=None, orient=None)
A sub-class of polars.DataFrame with additional functionality related to Model.
Two different methods are available for constructing model-aware data frames. Assume a simple model with two fields:
>>> import patito as pt >>> class Product(pt.Model): ... name: str ... price_in_cents: int ...
We can construct a data frame containing products and then associate the
Product
model to the data frame usingDataFrame.set_model
:>>> df = pt.DataFrame({"name": ["apple", "banana"], "price": [25, 61]}).set_model( ... Product ... )
Alternatively, we can use the custom
Product.DataFrame
class which automatically associates theProduct
model to the data frame at instantiation.>>> df = Product.DataFrame({"name": ["apple", "banana"], "price": [25, 61]})
The
df
data frame now has a set of model-aware methods such as as Product.validate.