JakobGM / patito

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

Nested literals not evaluated #68

Closed ion-elgreco closed 3 months ago

ion-elgreco commented 4 months ago

Nested literals in a list are not properly evaluated for invalid values, see example below:

import patito as pt
import polars as pl
from typing import Literal
class TestModel(pt.Model):
    foo: list[Literal['abc']]  = pt.Field(dtype=pl.List(pl.Utf8))

df = pl.DataFrame({
    "foo": [['wrong']]
})

TestModel.validate(df)

This should actually throw an error

ion-elgreco commented 4 months ago

@thomasaarholt @brendancooley fyi ;)

thomasaarholt commented 4 months ago

Thanks! I'll see if I can find time to look at it this week!

brendancooley commented 3 months ago

Taking a peak now, hopefully quick fix