unionai-oss / pandera

A light-weight, flexible, and expressive statistical data testing library

Home Page:https://www.union.ai/pandera

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pandera Series generic argument does not allow the `typing.List` etc. types

sam-goodwin opened this issue · comments

commented

Code Sample, a copy-pastable example

import pandera as pa
import pandera.typing as pdt

class MySchema(pa.DataFrameModel):
    int32: pdt.Series[list[pdt.Int32]] = pa.Field()

Run mypy and get the following error:

error: Type argument "list[Int32]" of "Series" must be a subtype of "bool | int | str | float | ExtensionDtype | Bool | Date | Timestamp | Decimal | Timedelta | Category | Float | Float16 | Float32 | Float64 | Int | Int8 | Int16 | Int32 | Int64 | UInt8 | UInt16 | UInt32 | UInt64 | INT8 | INT16 | INT32 | INT64 | UINT8 | UINT16 | UINT32 | UINT64 | Object | String | STRING | Geometry"  [type-var]

Expected behavior

The type checking should not fail.

@sam-goodwin feel free to make a PR to add the generic types here and here.

Also, FYI you can use the type without pdt.Series

    int32: pdt.list[pdt.Int32] = pa.Field()
commented

My plan was to fix this today.

RE: dropping the series type, I'm waiting for this PR to make its way into Pypi:

#1547

commented

Interesting, adding the types here is a new case as this is a recursive types. Would I add list[Any] or is there a better type for the parameter?

List[Any],
Dict[Any, Any],
Tuple[Any],
NamedTuple,