Skip to content

Series.argmin return type #591

@zmoon

Description

@zmoon

Describe the bug
I would expect Series.argmin() to have scalar integer return type, but the types seem not to match. First noticed with an error message like this:

error: Argument ... has incompatible type
"Optional[ndarray[Any, Any]]"; expected "Optional[int]"  [arg-type]

To Reproduce
Minimal example:

import pandas as pd

def f(i: int):
    print(df.iloc[i])

df = pd.DataFrame({"a": [-1, 0, 1], "b": [1, 2, 3]})
i = df.a.abs().argmin()

f(i)
> mypy t.py
t.py:9: error: Argument 1 to "f" has incompatible type "ndarray[Any, Any]"; expected "int"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:

  • OS: Windows
  • OS Version: 10 22H2
  • Python version: 3.9.13
  • version of type checker: mypy 1.1.1
  • version of installed pandas-stubs: 1.5.3.230321

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions