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

Cannot have type `List[str]`? - `TypeError: Cannot interpret 'typing.List[str]' as a data type` #1062

Closed fzyzcjy closed 1 year ago

fzyzcjy commented 1 year ago

Describe the bug

Hi thanks for the lib! But it seems that I cannot have type List[str] in a series

A clear and concise description of what the bug is.

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
from typing import List

import pandera as pa
from pandera.typing import Series, DataFrame

class MySchema(pa.SchemaModel):
    # my_field: Series[str] = pa.Field()
    my_field: Series[List[str]] = pa.Field()

df = DataFrame[MySchema](dict(
    my_field=[
        # [1]
        ['a']
    ]
))
print(df)

Expected behavior

A clear and concise description of what you expected to happen.

  1. If use type List[str], it should only accept values when it is a list of str -- but currently it is not
  2. If use type str, it should throw if the value is a list of str -- but currently it is not

Desktop (please complete the following information):

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

cosmicBboy commented 1 year ago

hi @fzyzcjy this is pretty much captured in https://github.com/unionai-oss/pandera/issues/260, gonna close this issue out as a duplicate. Feel free to chime in at #260 and open up a PR if you're open to contribute!