Index.__init__(pandas_dtype=None, checks=None, nullable=False, allow_duplicates=True, coerce=False, name=None)[source]

Create Index validator.

  • pandas_dtype (Union[str, type, PandasDtype, ExtensionDtype, None]) – datatype of the column. A PandasDtype for type-checking dataframe. If a string is specified, then assumes one of the valid pandas string values:

  • checks (Union[Check, Hypothesis, List[Union[Check, Hypothesis]], None]) – checks to verify validity of the index.

  • nullable (bool) – Whether or not column can contain null values.

  • allow_duplicates (bool) – Whether or not to coerce the column to the specified pandas_dtype before validation

  • coerce (bool) – If True, when schema.validate is called the index will be coerced into the specified dtype.

  • name (Optional[str]) – name of the index


>>> import pandas as pd
>>> import pandera as pa
>>> schema = pa.DataFrameSchema(
...     columns={"column": pa.Column(pa.String)},
...     index=pa.Index(pa.Int, allow_duplicates=False))
>>> schema.validate(
...     pd.DataFrame({"column": ["foo"] * 3}, index=range(3))
... )
0    foo
1    foo
2    foo

See here for more usage details.

Return type