-
-
Notifications
You must be signed in to change notification settings - Fork 297
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
Inconsistent support of type hints with mypy #1389
Comments
Hi @miguel-mi-silva if you're using @check_types
def process(df: TypeDataFrame[InputSchema]) -> TypeDataFrame[OutputSchema]:
return df.assign(c="c")
|
Thanks for that. However, even with those changes, the error on the return type Here's the new code to facilitate: from pandera import SchemaModel, check_types
from pandas import DataFrame
from pandera.typing import DataFrame as TypeDataFrame
class InputSchema(SchemaModel):
a: int
b: bool
class OutputSchema(SchemaModel):
a: int
b: bool
c: str
df = DataFrame({"a": [1], "b": [True]})
@check_types
def process(df: TypeDataFrame[InputSchema]) -> TypeDataFrame[OutputSchema]:
return df.assign(c="c") |
What does your See the docs for a discussion on mypy support. If you care about type lints there's some guidance there on how to make you mypy linting pass, e.g. @check_types
def process(df: TypeDataFrame[InputSchema]) -> TypeDataFrame[OutputSchema]:
return df.assign(c="c").pipe(TypeDataFrame[OutputSchema]) or from typing import cast
@check_types
def process(df: TypeDataFrame[InputSchema]) -> TypeDataFrame[OutputSchema]:
return cast(TypeDataFrame[OutputSchema], df.assign(c="c")) |
Describe the bug
I have read through the documentation and a few issues here (example), but could not find if this is a bug or not yet supported. From the discussion on the above link, it seems that it should be supported.
The bugs are:
check_input
orcheck_output
does not recognizeSchemaModel
as valid type.Code Sample, a copy-pastable example
Expected behavior
Running mypy on this code should not raise any errors (this is how I understand it, based on this reply to a previous issue).
However, the following errors are raised:
Argument "schema" to "check_input" has incompatible type "type[InputSchema]"; expected "DataFrameSchema | SeriesSchema" [arg-type]
Argument "schema" to "check_output" has incompatible type "type[OutputSchema]"; expected "DataFrameSchema | SeriesSchema" [arg-type]
Incompatible return value type (got "pandas.core.frame.DataFrame", expected "pandera.typing.pandas.DataFrame[OutputSchema]") [return-value]
Argument 1 to "process" has incompatible type "pandas.core.frame.DataFrame"; expected "pandera.typing.pandas.DataFrame[InputSchema]" [arg-type]
Additional context
Pandera version:
0.17.2
Mypy version:
1.6.0
Pandas version:
2.1.1
The text was updated successfully, but these errors were encountered: