Skip to content

Series.map() needs type for arg and result #941

Closed
@Dr-Irv

Description

@Dr-Irv

Specifically i am trying to typehint this function:

def map_hitgroup(series: pd.Series[int]) -> pd.Series[str]:
    hitgroup_mapping: dict[int, str] = {
        0: "generic",
        1: "head",
        2: "chest",
        3: "stomach",
        4: "left arm",
        5: "right arm",
        6: "left leg",
        7: "right leg",
        8: "neck",
        10: "gear",
    }
    return series.map(
        hitgroup_mapping
    )

There are 2 issues here. The type hint for series.map says that the return type (parameter) is the same as the initial one, which is not the case here (but it still works when running it).

The other is that the type hint does not specify the argument type.

Which results in the classic unknown warning.

Is there anything that i can currently do to adress this or is there just no way with the stubs and pyright strict mode.

Originally posted by @JanEricNitschke in #940

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions