Skip to content

Type-Checking Issue with Pandas map Method Overloading #10782

@JollyFrolics

Description

@JollyFrolics

Describe the bug
The map method is overloaded into two variant.

    def map(
        self, func: PythonFuncType, na_action: str | None = None, **kwargs
    ) -> DataFrame:

    def map(
        self,
        arg: Callable | Mapping | Series,
        na_action: Literal["ignore"] | None = None,
    ) -> Series:

The second one being a valid call for the below code. But I get the error

main.py|30 col 57-58 error| Argument of type "dict[str, bool]" cannot be assigned to parameter "func" of type "PythonFuncType" in function "map"   Type "dict[str, bool]" is not assignable to type "PythonFuncType"

Which suggest it is not checking the other variant?

Code or Screenshots

import pandas as pd;

def mapDataFrame(df: DataFrame):
  d = {"Yes": True, "No": False};
  df["International plan"] = df["International plan"].map(d);

Third Party Library
name = "pandas"
version = "2.2.3"

VS Code extension or command-line
pyright 1.1.403 command-line

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions