Skip to content

ENH: Series Mapping na_action=ignore result is misleading. #47262

Open
@chapmanderek

Description

@chapmanderek

Is your feature request related to a problem?

More a misleading flag... When mapping a dictionary to a pandas series and using the na_action='ignore' i would expect it to ignore unknown values. Currently it replaces them with an NaN. For example:

pd.Series(['calf', 'foal', 'bunny']).map({'calf':'cow','bunny':'rabbit'}, na_action='ignore')

returns:

0       cow
1       NaN
2    rabbit

Describe the solution you'd like

I would expect it to ignore items that aren't in the dictionary instead of replacing them. I would expect this to be returned:

0       cow
1       foal
2    rabbit

The current behavior is problematic for large dataframes with many different elements in a series where perhaps you only want to rename some of them. In this case you would have to either do a replace for each one... or make a mapping for every one and hope you didn't miss one.

Describe alternatives you've considered

Trying to differentiate the current action of ignore and the action of ignoring-but-not-replacing will be difficult. Perhaps a new value for na_action of dont_replace so that it is very apparent what you are asking to happen with NaNs while keeping the current behavior (albeit confusing) of ignore.

Additional context

Similar-ish to #14210

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateNeeds DiscussionRequires discussion from core team before further actionSeriesSeries data structure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions