How to use SeriesSchema with pydantic? #712
-
Hi! I am having trouble getting a Series to work with pydantic. The closest I got was something like this: import pandera as pa
from pydantic import BaseModel
import pandas as pd
class TestModel(BaseModel):
s: pa.SeriesSchema
s = pd.Series(
{
"XXX": "AAA",
"YYY": "BBB"
}
)
# check that the series passes validation
validated = pa.SeriesSchema().validate(s)
model = TestModel(s=s)
print(model) Output:
The Integrations Documentation mentions that SeriesSchema should work with pydantic. Can anybody point me in the right direction on this? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
hey @cleboo ! So currently pydantic models don't allow for validating Basically the code you have there will only validate whether or not Once #688 is addressed you'll be able to validate series against Series-specific models |
Beta Was this translation helpful? Give feedback.
hey @cleboo ! So currently pydantic models don't allow for validating
pd.Series
againstpandera.SeriesSchema
Basically the code you have there will only validate whether or not
s
is aSeriesSchema
object or not, see the schemas defined in the unit tests here and its usage here as an exampleOnce #688 is addressed you'll be able to validate series against Series-specific models