pandera.Index

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

Validate types and properties of a DataFrame Index.

Create Index validator.

Parameters
  • 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: http://pandas.pydata.org/pandas-docs/stable/basics.html#dtypes

  • 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

Example

>>> 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))
... )
  column
0    foo
1    foo
2    foo

See here for more usage details.

Attributes

allow_duplicates

Whether to allow duplicate values.

checks

Return list of checks or hypotheses.

coerce

Whether to coerce series to specified type.

dtype

String representation of the dtype.

name

Get SeriesSchema name.

nullable

Whether the series is nullable.

pandas_dtype

Get the pandas dtype

Methods

__init__

Create Index validator.

coerce_dtype

Coerce type of a pd.Index by type specified in pandas_dtype.

validate

Validate DataFrameSchema or SeriesSchema Index.

__call__

Alias for validate method.