Skip to content

Commit

Permalink
add support for Any annotation in schema model
Browse files Browse the repository at this point in the history
the motivation behind this feature is to support column annotations
that can have any type, to support use cases like the one described
in #592, where
custom checks can be applied to any column except for ones that
are explicitly defined in the schema model class attributes
  • Loading branch information
cosmicBboy committed Sep 1, 2021
1 parent abc817f commit aca7960
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pandera/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ def _build_columns_index( # pylint:disable=too-many-locals
else:
dtype = annotation.arg

dtype = None if dtype is Any else dtype

if annotation.origin is Series:
col_constructor = (
field.to_column if field else schema_components.Column
Expand Down
5 changes: 3 additions & 2 deletions tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint:disable=missing-class-docstring,missing-function-docstring,too-few-public-methods
import re
from decimal import Decimal # pylint:disable=C0415
from typing import Iterable, Optional
from typing import Any, Iterable, Optional

import pandas as pd
import pytest
Expand All @@ -18,10 +18,11 @@ def test_to_schema() -> None:
class Schema(pa.SchemaModel):
a: Series[int]
b: Series[str]
c: Series[Any]
idx: Index[str]

expected = pa.DataFrameSchema(
columns={"a": pa.Column(int), "b": pa.Column(str)},
columns={"a": pa.Column(int), "b": pa.Column(str), "c": pa.Column()},
index=pa.Index(str),
)

Expand Down

0 comments on commit aca7960

Please sign in to comment.