Open
Description
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
Labels
Issue that has not been reviewed by a pandas team memberIssue that has not been reviewed by a pandas team member