Skip to content

API: In Series.map, change the default value for na_action to "ignore"" #52196

Open
@topper-123

Description

@topper-123

In Pandas 2.1, Series.map with the parameter na_ignore set to na_ignore="ignore" will work for all array types. (see #51809 + the various PRs that add na_action="ignore" to the various ExtensionArrays). Previously the support for na_action="ignore" was quite spotty.

IMO na_action="ignore" is a better default value than na_action=None (the current default), because 99 % of the time when I use .map, I want it to ignore Nans and assume it’s the same for others. E.g.:

>>> import numpy as np 
>>> import pandas as pd
>>> ser = pd.Series(["a", np.nan, "b"])
>>> ser.map(str.upper)
TypeError: descriptor 'upper' for 'str' objects doesn't apply to a 'float' object
>>> ser.map(str.upper, na_action="ignore")
0      A
1    NaN
2      B
dtype: object

So I propose deprecating None as the default for na_action in favor of "ignore".

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDeprecateFunctionality to remove in pandasNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions