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

Validation fails on an empty list #103

Closed
dhimmel opened this issue Oct 15, 2024 · 3 comments · Fixed by #107
Closed

Validation fails on an empty list #103

dhimmel opened this issue Oct 15, 2024 · 3 comments · Fixed by #107

Comments

@dhimmel
Copy link

dhimmel commented Oct 15, 2024

The following model validation fails on an empty list:

import polars as pl
from patito import Model

class TestModel(Model):
    list_field: list[str]

df = pl.DataFrame({"list_field": [["a", "b"], []]})
TestModel.validate(df)

With the error message:

DataFrameValidationError: 1 validation error for TestModel
list_field
  1 missing value in lists (type=value_error.missingvalues)

I would expect an empty list to validate as list[str], at least Pydantic thinks so:

from pydantic import BaseModel

class TestPydanticModel(BaseModel):
    list_field: list[str]

TestPydanticModel(list_field=[])  # happy
@dhimmel
Copy link
Author

dhimmel commented Oct 15, 2024

Changing to list_field: list[str | None] passes validation.

dhimmel added a commit to dhimmel/openskistats that referenced this issue Oct 15, 2024
@dsgibbons
Copy link
Contributor

dsgibbons commented Oct 16, 2024

Can you please rerun this from the main branch instead of the latest release and see if this is still an issue? If this is still an issue, it should be a pretty easy fix.

@dsgibbons
Copy link
Contributor

Ok I confirm this is present on main. Thank you for raising this.

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.

2 participants