Series SchemasΒΆ
The SeriesSchema
class allows for the validation of pandas
Series
objects, and are very similar to columns and
indexes described in DataFrameSchemas.
import pandas as pd
import pandera as pa
# specify multiple validators
schema = pa.SeriesSchema(
str,
checks=[
pa.Check(lambda s: s.str.startswith("foo")),
pa.Check(lambda s: s.str.endswith("bar")),
pa.Check(lambda x: len(x) > 3, element_wise=True)
],
nullable=False,
allow_duplicates=True,
name="my_series")
validated_series = schema.validate(
pd.Series(["foobar", "foobar", "foobar"], name="my_series"))
print(validated_series)
0 foobar
1 foobar
2 foobar
Name: my_series, dtype: object