Series SchemasΒΆ

SeriesSchemas allow for the validation of pd.Series objects, and are very similar to columns and indexes described in DataFrameSchemas.

import pandas as pd
import pandera as pa

from pandera import Check, SeriesSchema

# specify multiple validators
schema = SeriesSchema(
    pa.String,
    checks=[
        Check(lambda s: s.str.startswith("foo")),
        Check(lambda s: s.str.endswith("bar")),
        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