class pandera.api.pandas.container.DataFrameSchema(columns=None, checks=None, parsers=None, index=None, dtype=None, coerce=False, strict=False, name=None, ordered=False, unique=None, report_duplicates='all', unique_column_names=False, add_missing_columns=False, title=None, description=None, metadata=None, drop_invalid_rows=False)[source]

A light-weight pandas DataFrame validator.

Initialize DataFrameSchema validator.

  • columns (mapping of column names and column schema component.) – a dict where keys are column names and values are Column objects specifying the datatypes and properties of a particular column.

  • checks (Union[Check, List[Union[Check, Hypothesis]], None]) – dataframe-wide checks.

  • parsers (Union[Parser, List[Parser], None]) – dataframe-wide parsers.

  • index – specify the datatypes and properties of the index.

  • dtype (Optional[Any, None]) – datatype of the dataframe. This overrides the data types specified in any of the columns. If a string is specified, then assumes one of the valid pandas string values:

  • coerce (bool) – whether or not to coerce all of the columns on validation. This overrides any coerce setting at the column or index level. This has no effect on columns where dtype=None.

  • strict (Union[bool, Literal[‘filter’]]) – ensure that all and only the columns defined in the schema are present in the dataframe. If set to ‘filter’, only the columns in the schema will be passed to the validated dataframe. If set to filter and columns defined in the schema are not present in the dataframe, will throw an error.

  • name (Optional[str, None]) – name of the schema.

  • ordered (bool) – whether or not to validate the columns order.

  • unique (Union[str, List[str], None]) – a list of columns that should be jointly unique.

  • report_duplicates (Union[Literal[‘exclude_first’], Literal[‘exclude_last’], Literal[‘all’]]) – how to report unique errors - exclude_first: report all duplicates except first occurence - exclude_last: report all duplicates except last occurence - all: (default) report all duplicates

  • unique_column_names (bool) – whether or not column names must be unique.

  • add_missing_columns (bool) – add missing column names with either default value, if specified in column schema, or NaN if column is nullable.

  • title (Optional[str, None]) – A human-readable label for the schema.

  • description (Optional[str, None]) – An arbitrary textual description of the schema.

  • metadata (Optional[dict, None]) – An optional key-value data.

  • drop_invalid_rows (bool) – if True, drop invalid rows on validation.


SchemaInitError – if impossible to build schema from parameters


>>> import pandera as pa
>>> schema = pa.DataFrameSchema({
...     "str_column": pa.Column(str),
...     "float_column": pa.Column(float),
...     "int_column": pa.Column(int),
...     "date_column": pa.Column(pa.DateTime),
... })

Use the pandas API to define checks, which takes a function with the signature: pd.Series -> Union[bool, pd.Series] where the output series contains boolean values.

>>> schema_withchecks = pa.DataFrameSchema({
...     "probability": pa.Column(
...         float, pa.Check(lambda s: (s >= 0) & (s <= 1))),
...     # check that the "category" column contains a few discrete
...     # values, and the majority of the entries are dogs.
...     "category": pa.Column(
...         str, [
...             pa.Check(lambda s: s.isin(["dog", "cat", "duck"])),
...             pa.Check(lambda s: (s == "dog").mean() > 0.5),
...         ]),
... })

See here for more usage details.




Whether to coerce series to specified type.


Get the dtype property.


A dict where the keys are column names and values are DataType s for the column.


Get the properties of the schema for serialization purposes.


List of columns that should be jointly unique.



Validate a DataFrame based on the schema specification.


Alias for DataFrameSchema.validate() method.