Skip to content

Type checking is not working for parameters entered inline with a function #412

Closed

Description

@williamjamir

Describe the bug
Not sure if this is the correct project to report this issue; it may look like a mypy issue, but I could not reproduce it with any example that was not from pandas-stubs.

Mypy is not complaining about a wrong pd.Series when passing directly in a function.

To Reproduce

Example not displaying error:

from __future__ import annotations

import pandas as pd

def some_function(param: pd.Series[str]) -> pd.Series[float]:
    return param.astype(float)

some_function(param=pd.Series([1.0, 1.0, 1.0], dtype=float)

mypy doesn't complain

>>>mypy test.py                                                   
Success: no issues found in 1 source file

But, if this value is kept in a variable, the error is shown.

from __future__ import annotations

import pandas as pd


def some_function(param: pd.Series[str]) -> pd.Series[float]:
    return param.astype(float)


some_value = pd.Series([1.0, 1.0, 1.0], dtype=float)
some_function(some_value)
>>> mypy test.py
/tmp/test.py:11: error: Argument 1 to "some_function" has incompatible type "Series[float]"; expected "Series[str]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:

  • OS: MacOS M1

  • OS Version Ventura 13.0

  • python version: 3.9.12 (Can see the same issue on Python 3.10)

  • version of type checker: mypy 0.982 (compiled: yes)

  • version of installed pandas-stubs
    pandas==1.5.1
    pandas-stubs==1.5.1.221024

Additional context
Add any other context about the problem here.

Activity

  1. changed the title [-]Issue not [/-] [+]Type checking is not working for parameters entered inline with a function[/+] on Nov 4, 2022
  2. Dr-Irv commented on Nov 4, 2022

    @Dr-Irv
    Collaborator

    It's a mypy bug. I just reported it here: python/mypy#14009

  3. Dr-Irv commented on Nov 20, 2022

    @Dr-Irv
    Collaborator

    Still a mypy bug in version 0.990

  4. Dr-Irv commented on Aug 15, 2023

    @Dr-Irv
    Collaborator

    Based on discussion in python/mypy#14009 (see python/mypy#14009 (comment) ), this is a subtle feature of how type checkers work.

    So we can't fix this because we need to support Series with unspecified types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    mypy bugRequires mypy to fix a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions