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: Allow s.map(d, na_action='raise') #60482

Open
wants to merge 12 commits 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 (without checking the original series beforehand due to their expectations) 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 example here also shows how a typo in the input data can cause unwanted trouble.

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.

Copy link
Contributor

github-actions bot commented Jan 3, 2025

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Jan 3, 2025
@kopytjuk kopytjuk force-pushed the add-raise-to-series-map branch from 756b49f to 5efce7b Compare March 7, 2025 08:05
@kopytjuk kopytjuk changed the title ENH: Implement map_array(na_action='raise') ENH: Implement s.map(d, na_action='raise') Mar 7, 2025
@kopytjuk kopytjuk changed the title ENH: Implement s.map(d, na_action='raise') ENH: Allow s.map(d, na_action='raise') Mar 7, 2025
@kopytjuk
Copy link
Contributor Author

kopytjuk commented Mar 7, 2025

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

Still interested!

@kopytjuk
Copy link
Contributor Author

kopytjuk commented Mar 8, 2025

Sorry for pinging @mroeschke - can you please spend a quick glimpse on that, if the design and the goal is worth following ... thank you in advance!

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

Successfully merging this pull request may close these issues.

1 participant