Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
topper-123 opened this issue Mar 25, 2023 · 0 comments
Open
Labels
API Design Deprecate Functionality to remove in pandas Needs Discussion Requires discussion from core team before further action

Comments

@topper-123
Copy link
Contributor

topper-123 commented Mar 25, 2023

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".

@phofl phofl added API Design Deprecate Functionality to remove in pandas Needs Discussion Requires discussion from core team before further action labels Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Deprecate Functionality to remove in pandas Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

2 participants