Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Any annotation in schema model #594

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repos:
args: ["--line-length=79"]

- repo: https://github.com/pycqa/pylint
rev: pylint-2.7.2
rev: v2.10.2
hooks:
- id: pylint
args: ["--disable=import-error"]
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _build_setup_requirements() -> Dict[str, List[Requirement]]:

def _build_dev_requirements() -> List[Requirement]:
"""Load requirements from file."""
with open(REQUIREMENT_PATH, "rt") as req_file:
with open(REQUIREMENT_PATH, "rt", encoding="utf-8") as req_file:
return list(parse_requirements(req_file.read()))


Expand Down
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
4 changes: 3 additions & 1 deletion tests/core/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def validate_inplace(df):
for out_schema in [1, 5.0, "foo", {"foo": "bar"}, ["foo"]]:

# mypy finds correctly the wrong usage
# pylint: disable=cell-var-from-loop
@check_io(out=out_schema) # type: ignore[arg-type]
def invalid_out_schema_type(df):
return df
Expand Down Expand Up @@ -688,7 +689,8 @@ def test_check_types_with_literal_type(arg_examples):
@check_types
def transform_with_literal(
df: DataFrame[InSchema],
arg: arg_type, # pylint: disable=unused-argument
# pylint: disable=unused-argument,cell-var-from-loop
arg: arg_type,
) -> DataFrame[OutSchema]:
return df.assign(b=100)

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