Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Broaden dict to Mapping as replace argument #61440

Copy link
Copy link
Open
@DavideCanton

Description

@DavideCanton
Issue body actions

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

Currently the replace method of Series allows only dict, but not Mapping inputs, as the DataFrame one does.

For example:

from collections.abc import Mapping
import pandas as pd


df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})

d: Mapping[int, str] = {1: "a", 2: "b", 3: "c"}

d2: Mapping[str, Mapping[int, str]] = {"A": d}
print(df.replace(d2))  # typechecks

print(df["A"].replace(d))  # works but doesn't typecheck

Feature Description

I guess it's enough to change from dict to Mapping in the type signature, since it seems to work even if the argument is not a dict (for example if it's a MappingProxyType instance).

Alternative Solutions

I guess an alternative solution is just to type ignore the replace invocation.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team memberIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.