JakobGM / patito

A data modelling layer built on top of polars and pydantic
MIT License
270 stars 23 forks source link

Restriction of `Field` are not applied to the `examples` function #13

Closed raui100 closed 3 weeks ago

raui100 commented 1 year ago

The following code raises an ValidationError because a is assigned -0.5 as float by Product.examples() even though a is restricted to be >=0.0:

import patito as pt
class Product(pt.Model):
    a: float = pt.Field(ge=0.0)

if __name__ == "__main__":
    p = Product.examples()
    print(p["a"][0])  # "-0.5"
    Product.validate(Product.examples())  # ValidationError
ion-elgreco commented 12 months ago

Yup, running into the same issue now. Now I've had to manually provide a value in the examples for these fields. However the issue seems to be only for ge

Issue is here: https://github.com/JakobGM/patito/blob/77923db45194acea7de49be8194100870833e982/src/patito/pydantic.py#L759-L762C4

I'll open up a pr for it

raui100 commented 3 weeks ago

Has been fixed!