Skip to content

ERR: Raise on invalid na_action in Series.map #32790

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

Merged
merged 20 commits into from
Mar 22, 2020
Merged

ERR: Raise on invalid na_action in Series.map #32790

merged 20 commits into from
Mar 22, 2020

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented Mar 17, 2020

  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Series.map treats any na_action other than "ignore" like None, but it should probably raise if someone provides an invalid option:

In [1]: import pandas as pd                                                                                                                                

In [2]: pd.Series([1, 2, 3]).map(lambda x: x, na_action="xxxxx")                                                                                           
Out[2]: 
0    1
1    2
2    3
dtype: int64

@jbrockmendel
Copy link
Member

Do any Index methods need the same fix?

@dsaxton
Copy link
Member Author

dsaxton commented Mar 17, 2020

Do any Index methods need the same fix?

Looks like they do. Actually it seems worse, e.g. ExtensionIndex just ignores na_action: https://github.com/pandas-dev/pandas/blob/master/pandas/core/indexes/extension.py#L291

Edit: Tried fixing this and wasn't able to without introducing more bugs. Opened this issue instead: #32815.

map_f = lib.map_infer
else:
raise ValueError("na_action must either be 'ignore' or None")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add: f`{na_action} was passed

@@ -787,3 +787,9 @@ def test_map_float_to_string_precision(self):
result = ser.map(lambda val: str(val)).to_dict()
expected = {0: "0.3333333333333333"}
assert result == expected

def test_map_with_invalid_na_action_raises(self):
s = pd.Series([1, 2, 3])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the issue umber as a comment

@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Mar 19, 2020
@jreback jreback added this to the 1.1 milestone Mar 19, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. merge master and ping on green.

@dsaxton
Copy link
Member Author

dsaxton commented Mar 21, 2020

lgtm. merge master and ping on green.

@jreback Merged master and green, thanks for reviewing

@jreback jreback merged commit 8b4491f into pandas-dev:master Mar 22, 2020
@jreback
Copy link
Contributor

jreback commented Mar 22, 2020

thanks

@dsaxton dsaxton deleted the map-na-action branch March 22, 2020 00:14
SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request Mar 22, 2020
jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants