unionai-oss / pandera

A light-weight, flexible, and expressive statistical data testing library
https://www.union.ai/pandera
MIT License
3.38k stars 310 forks source link

mypy: pa.typing.Series does not support pd.DatetimeTZDtype as a type argument #959

Closed DXsmiley closed 2 years ago

DXsmiley commented 2 years ago

Describe the bug

Under mypy, pa.typing.Series does not support pd.DatetimeTZDtype as a valid type argument.

Bug occurs with and without pandera.mypy plugin

Code Sample, a copy-pastable example

from typing import Annotated
import pandas as pd
import pandera as pa
from pandera.typing import Series

class MySchema(pa.SchemaModel):
    # both lines taken from the pandera documentation
    a: Series[Annotated[pd.DatetimeTZDtype, "ns", "UTC"]]
    b: Series[pd.DatetimeTZDtype] = pa.Field(dtype_kwargs={"unit": "ns", "tz": "UTC"})

Expected behavior

mypy should show no errors

Actual behaviour

mypy produces the following errors

test.py:8: error: Value of type variable "GenericDtype" of "Series" cannot be "DatetimeTZDtype"
test.py:9: error: Value of type variable "GenericDtype" of "Series" cannot be "DatetimeTZDtype"

Versions

pandas==1.5.0
pandas-stubs==1.4.3.220807
pandera==0.13.3
mypy==0.982
mypy-extensions==0.4.3
cosmicBboy commented 2 years ago

hi @DXsmiley, #960 should fix this!