Model with index example#
Pandera Single Index Schema#
import pandera.pandas as pa
single_index_schema = pa.DataFrameSchema(
index=pa.Index(
str,
unique=True,
checks=[
pa.Check.str_matches(r"^AIPE-[0-9]+$"),
],
name="key",
title="First Index type field",
description="Field whose dtype is Index",
),
strict=True,
coerce=True,
description="Schema with a single field which is a pandas index",
)
multi_index_schema = pa.DataFrameSchema(
index=pa.MultiIndex(
[
pa.Index(
str,
unique=True,
checks=[
pa.Check.str_matches(r"^AIPE-[0-9]+$"),
],
name="key1",
title="First Index type field",
description="Field whose dtype is Index",
),
pa.Index(
str,
unique=True,
checks=[
pa.Check.str_matches(r"^AIPE2-[0-9]+$"),
],
name="key2",
title="Second Index type field",
description="Field whose dtype is Index",
),
]
),
strict=True,
coerce=True,
description="Schema with two fields which are a pandas index (multiIndex)",
)
- pandera schema target.index_schema.single_index_schema#
Schema with a single field which is a pandas index
- Schema Configuration:
coerce = True
ordered = False
strict = True
.. autopandera_schema:: target.index_schema.single_index_schema
NB: If you want to use markdown with myst-parser, use the eval-rst directive.
Pandera MultiIndex Schema#
import pandera.pandas as pa
single_index_schema = pa.DataFrameSchema(
index=pa.Index(
str,
unique=True,
checks=[
pa.Check.str_matches(r"^AIPE-[0-9]+$"),
],
name="key",
title="First Index type field",
description="Field whose dtype is Index",
),
strict=True,
coerce=True,
description="Schema with a single field which is a pandas index",
)
multi_index_schema = pa.DataFrameSchema(
index=pa.MultiIndex(
[
pa.Index(
str,
unique=True,
checks=[
pa.Check.str_matches(r"^AIPE-[0-9]+$"),
],
name="key1",
title="First Index type field",
description="Field whose dtype is Index",
),
pa.Index(
str,
unique=True,
checks=[
pa.Check.str_matches(r"^AIPE2-[0-9]+$"),
],
name="key2",
title="Second Index type field",
description="Field whose dtype is Index",
),
]
),
strict=True,
coerce=True,
description="Schema with two fields which are a pandas index (multiIndex)",
)
- pandera schema target.index_schema.multi_index_schema#
Schema with two fields which are a pandas index (multiIndex)
- Schema Configuration:
coerce = True
ordered = False
strict = True
.. autopandera_schema:: target.index_schema.multi_index_schema
NB: If you want to use markdown with myst-parser, use the eval-rst directive.
Pandera Single index Model#
import pandera.pandas as pa
from pandera.typing.pandas import Index
class TestSingleIndexModel(pa.DataFrameModel):
"""
Model with a single field which is a pandas index
"""
# pylint: disable=too-few-public-methods
class Config:
strict = True
coerce = True
key: Index[str] = pa.Field(
unique=True,
check_name=True,
str_matches=r"^AIPE-[0-9]+$",
title="First Index type field",
description="Field whose dtype is Index",
)
class TestMultiIndexModel(pa.DataFrameModel):
"""
Model with two fields which are a pandas index (multiIndex)
"""
# pylint: disable=too-few-public-methods
class Config:
strict = True
coerce = True
key1: Index[str] = pa.Field(
unique=True,
check_name=True,
str_matches=r"^AIPE-[0-9]+$",
title="First Index type field",
description="Field whose dtype is Index",
)
key2: Index[str] = pa.Field(
unique=True,
check_name=True,
str_matches=r"^AIPE2-[0-9]+$",
title="Second Index type field",
description="Field whose dtype is Index",
)
.. autopandera_model:: target.index_model.TestSingleIndexModel
NB: If you want to use markdown with myst-parser, use the eval-rst directive.
Pandera MultiIndex Model#
import pandera.pandas as pa
from pandera.typing.pandas import Index
class TestSingleIndexModel(pa.DataFrameModel):
"""
Model with a single field which is a pandas index
"""
# pylint: disable=too-few-public-methods
class Config:
strict = True
coerce = True
key: Index[str] = pa.Field(
unique=True,
check_name=True,
str_matches=r"^AIPE-[0-9]+$",
title="First Index type field",
description="Field whose dtype is Index",
)
class TestMultiIndexModel(pa.DataFrameModel):
"""
Model with two fields which are a pandas index (multiIndex)
"""
# pylint: disable=too-few-public-methods
class Config:
strict = True
coerce = True
key1: Index[str] = pa.Field(
unique=True,
check_name=True,
str_matches=r"^AIPE-[0-9]+$",
title="First Index type field",
description="Field whose dtype is Index",
)
key2: Index[str] = pa.Field(
unique=True,
check_name=True,
str_matches=r"^AIPE2-[0-9]+$",
title="Second Index type field",
description="Field whose dtype is Index",
)
- pandera model target.index_model.TestMultiIndexModel[source]#
Model with two fields which are a pandas index (multiIndex)
.. autopandera_model:: target.index_model.TestMultiIndexModel
NB: If you want to use markdown with myst-parser, use the eval-rst directive.