Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: pt.Field applying validation checks also on None values #11

Closed
ion-elgreco opened this issue Sep 4, 2023 · 1 comment · Fixed by #32
Closed

bug: pt.Field applying validation checks also on None values #11

ion-elgreco opened this issue Sep 4, 2023 · 1 comment · Fixed by #32

Comments

@ion-elgreco
Copy link

ion-elgreco commented Sep 4, 2023

edit: I see this inherited from PyDantic, so probably root issue is there.

I have a df with the following field

class Table(pt.Model):
    score: float | None = pt.Field(ge=0, le=1)

The score can be None, but if it's a float it should be between 0 and 1. However, patito is applying this validation checks on all rows, essentially completely ignoring the fact that I allow it too also be a None. Which results in this error:

ValidationError: 1 validation errors for Table
score
  13183196 rows with out of bound values. (type=value_error.rowvalue)
@ion-elgreco ion-elgreco changed the title pt.Field applying validation checks also on None values bug: pt.Field applying validation checks also on None values Sep 4, 2023
@ion-elgreco
Copy link
Author

ion-elgreco commented Sep 4, 2023

Solved it by just using polars constraints:

constrainted_field= pt.Field(
    constraints=pl.when(pt.field.is_not_null()).then((pt.field >= 0) & (pt.field <= 1)).otherwise(True)
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant