Skip to content
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

Mypy type hinting error for direct column type annotations #1681

Open
2 of 3 tasks
Girmii opened this issue Jun 13, 2024 · 0 comments
Open
2 of 3 tasks

Mypy type hinting error for direct column type annotations #1681

Girmii opened this issue Jun 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Girmii
Copy link

Girmii commented Jun 13, 2024

Describe the bug
A clear and concise description of what the bug is.

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandera.
  • (optional) I have confirmed this bug exists on the main branch of pandera.

Mypy throws an error when using DataFrameModel field names as strings with the direct column type annotations.

Code Sample, a copy-pastable example

import pandera as pa
from pandera.typing import Series


class A(pa.DataFrameModel):
    b: float = pa.Field(nullable=False)
    c: Series[float] = pa.Field(nullable=False)


def print_string(string: str):
    print(f"type: {type(string)}, value: {string}")


if __name__ == "__main__":
    print_string(A.b)  # line 15
    print_string(A.c)

Script output

type: <class 'str'>, value: b
type: <class 'str'>, value: c

Mypy output

src/pandera_typing.py:15: error: Argument 1 to "print_string" has incompatible type "float"; expected "str"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Expected behavior

I would expect the type hinting to be consistent across the explicit and implicit column type annotation, and thus for Mypy to interpret the direct column annotation names as a strings.

Versions:

  • Python 3.11.0
  • pandas==2.2.0
  • pandas-stubs==2.1.4.231227
  • pandera==0.19.3
  • mypy 1.10.0 (compiled: yes)
@Girmii Girmii added the bug Something isn't working label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant