Open ion-elgreco opened 11 months ago
I have just tried this on Patito 0.6.1 and it works fine:
>>> import patito as pt
>>> class Test(pt.Model):
... col: list[str]
...
>>> class InhTest(Test):
... pass
...
>>> df = InhTest.examples({"col": [["Hello"]]})
>>> df
shape: (1, 1)
┌───────────┐
│ col │
│ --- │
│ list[str] │
╞═══════════╡
│ ["Hello"] │
└───────────┘
>>> print(Test.__annotations__)
{'col': list[str]}
>>> print(InhTest.__annotations__)
{'col': list[str]}
>>> InhTest.validate(df)
>>> df2 = InhTest.examples({"col": [["Hello", "Bye", 1]]})
>>> df2
shape: (1, 1)
┌────────────────────────┐
│ col │
│ --- │
│ list[str] │
╞════════════════════════╡
│ ["Hello", "Bye", null] │
└────────────────────────┘
>>> InhTest.validate(df2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sam/Documents/GitHub/filebasedbim/venv/lib/python3.12/site-packages/patito/pydantic.py", line 498, in validate
validate(dataframe=dataframe, columns=columns, schema=cls, **kwargs)
File "/Users/sam/Documents/GitHub/filebasedbim/venv/lib/python3.12/site-packages/patito/validators.py", line 342, in validate
raise DataFrameValidationError(errors=errors, model=schema)
patito.exceptions.DataFrameValidationError: 1 validation error for InhTest
col
1 missing value in lists (type=value_error.missingvalues)
>>> Test.validate(df2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sam/Documents/GitHub/filebasedbim/venv/lib/python3.12/site-packages/patito/pydantic.py", line 498, in validate
validate(dataframe=dataframe, columns=columns, schema=cls, **kwargs)
File "/Users/sam/Documents/GitHub/filebasedbim/venv/lib/python3.12/site-packages/patito/validators.py", line 342, in validate
raise DataFrameValidationError(errors=errors, model=schema)
patito.exceptions.DataFrameValidationError: 1 validation error for Test
col
1 missing value in lists (type=value_error.missingvalues)
>>>
Assume that this can be closed?
This is going to cause an issue when you want to validate the list column:
Reproducible example: