-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Series map ignoring na_action for dict or series mapper #47585
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since there is quite a few paths through here, might be worth adding tests for categorical Series and also using a mapping that doesn't get converted to a series above.
I was quite happy to not treat this as a bug and just update the docs, see #46588 (comment) and #46588 (comment)
but it appears that @rhshadrach is happy to consider it a bug #47527 (comment)
so if we are honoring the
na_action
for types other than callables, it should probably be tested for the default dict case too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh! and change the docstring too.
without passing them to the mapping function -> without passing them to the mapping`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I would be ok with treating this ok as is, what do you think @rhshadrach ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm also happy to treat it as a bug, but also consider it an enhancement so that we have a few more tests than a regular bugfix. (although we might already test)
I assume (not tried) that the default dict case goes through as a function and already honors the
na_action
and therefore no extra code needed. This also would be a good argument for treating it as a bug since the default dict case and regular dict are currently inconsistent?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm good point, but defaultdict seems to be off
This should return
Series([10, 42, x])
where x is None? 2? Not sure, but this returns
Series([10, 0, 0])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm +1 on either option here - fixing the behavior to match the current docs or changing the docs as @simonjayhawkins has suggested. I'd lean toward the latter, but not strongly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second
0
(index 2) looks correct, but index 1 returning0
too looks incorrect.Ignore for a minute the latent bug identified above, when I made those comments I didn't appreciate that a
defaultdict
would take the same path as a callable and hence already takes account of thena_action
kwarg.So for consistency, i'm now favoring the the first option. (i.e generally happy with this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with the first zero (at index 1) in #47585 (comment) appears to be due to using np.nan in a dictionary:
Because one gets a view of np.nan, the ids are different and therefore lookup fails. This is "expected" behavior when working with np.nan in a dictionary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this makes sense, thanks very much. I’ll add additional tests and then this should be ready I think