1

I want to define a type to be a DataFrame with a particular pandera schema. However, when I lint this code:

from pandera.typing import DataFrame, Series


class MySchema(pa.SchemaModel):
    foo: Series[str]

MyDF = DataFrame[MySchema]

def myfun(df: MyDF) -> bool:
    return True

I get

myproject: myfile.py: note: In function "myfun":
myproject: myfile.py:10:15: error: Variable "myproject.myproject.myfile.MyDF" is not valid as a type  [valid-type]

I understand I can avoid this error by specifying df: DataFrame[MySchema] in the signature of myfun instead. Is there some way I can define the alias MyDF in a valid manner?

Mose Wintner
  • 290
  • 1
  • 10

0 Answers0