pandera.core.pandas.components.MultiIndex#
- class pandera.core.pandas.components.MultiIndex(indexes, coerce=False, strict=False, name=None, ordered=True, unique=None)[source]#
Validate types and properties of a DataFrame MultiIndex.
This class inherits from
DataFrameSchemato leverage its validation logic.Create MultiIndex validator.
- Parameters
indexes (
List[Index]) – list of Index validators for each level of the MultiIndex index.coerce (
bool) – Whether or not to coerce the MultiIndex to the specified dtypes before validationstrict (
bool) – whether or not to accept columns in the MultiIndex that aren’t defined in theindexesargument.ordered (
bool) – whether or not to validate the indexes order.unique (
Union[str,List[str],None]) – a list of index names that should be jointly unique.
- Example
>>> import pandas as pd >>> import pandera as pa >>> >>> >>> schema = pa.DataFrameSchema( ... columns={"column": pa.Column(int)}, ... index=pa.MultiIndex([ ... pa.Index(str, ... pa.Check(lambda s: s.isin(["foo", "bar"])), ... name="index0"), ... pa.Index(int, name="index1"), ... ]) ... ) >>> >>> df = pd.DataFrame( ... data={"column": [1, 2, 3]}, ... index=pd.MultiIndex.from_arrays( ... [["foo", "bar", "foo"], [0, 1, 2]], ... names=["index0", "index1"], ... ) ... ) >>> >>> schema.validate(df) column index0 index1 foo 0 1 bar 1 2 foo 2 3
See here for more usage details.
Attributes
BACKENDcoerceWhether or not to coerce data types.
dtypeGet the dtype property.
dtypesA dict where the keys are column names and values are
DataTypes for the column.namesGet index names in the MultiIndex schema component.
propertiesGet the properties of the schema for serialization purposes.
uniqueList of columns that should be jointly unique.
Methods