Skip to content
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

ENH: Implement map_array(na_action='raise') #60482

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kopytjuk
Copy link
Contributor

@kopytjuk kopytjuk commented Dec 3, 2024

Addresses #14210

Often users use s.map() blindly and are surprised by downstream errors which are caused by the implicit replacement of values to np.nan if they are not part of the mapping dictionary:

import pandas as pd

s = pd.Series(["cat", "dog", "mouse"])
d = {"cat": "kitten", "dog": "puppy"}

res = s.map(d)

print(res)
# 0    kitten
# 1     puppy
# 2       NaN
# dtype: object

This PR adds a possibility to raise an error via s.map(d, na_option='raise'), if the mapping does not cover all values in the array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant