-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Allow indices to be mapped through through dictionaries or series #15081
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
22 commits
Select commit
Hold shift + click to select a range
c8d2a80
Allow index.map() to accept series and dictionary inputs in addition …
nateyoder 9a67ffd
add test to make sure dictionaries with missing keys work
nateyoder 2b70597
Refactor the code to work with period time time delta indices
nateyoder 80ca2e2
Makes changes based on feedback from @jreback
nateyoder 00165c4
Using numpy array from return if possible
nateyoder 2f019c5
Update tests to include empty maps and NaT values
nateyoder f6a2404
Refactor map to use common code for series and index when possible an…
nateyoder 0c72a38
Fix bug related to converting a dictionary to a MultiIndex instead of…
nateyoder 73c276b
pep8 fixes
nateyoder a858467
Address comments from @jreback add new tests; skip tests on IntervalI…
nateyoder 68479a3
Fix issues from merge
nateyoder 80a4c9c
Fix issues from merge
nateyoder 30e7e7a
replace _constructor
jreback 25bba86
Merge branch 'master' into PR_TOOL_MERGE_PR_15081
jreback 51c5b2b
move whatsnew
jreback 8f0198e
unify _map_values a bit more
jreback 80fad28
use an efficient path for mapping
jreback 5006b24
restore name of mapper in .map
jreback 4134641
more renaming
jreback 096b0e6
Merge branch 'master' into PR_TOOL_MERGE_PR_15081
jreback c0f3b76
review comments
jreback dd0b7e9
handle empty maps
jreback 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 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 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 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 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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1457,6 +1457,17 @@ def get_value_maybe_box(self, series, key): | |
key, tz=self.tz) | ||
return _maybe_box(self, values, series, key) | ||
|
||
@Appender(_index_shared_docs['_get_values_from_dict']) | ||
def _get_values_from_dict(self, data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is needed for datetimeliek then push this to the super class rather than having 2 impls. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the above comment. |
||
if len(data): | ||
# coerce back to datetime objects for lookup | ||
data = com._dict_compat(data) | ||
return lib.fast_multiget(data, | ||
self.asobject.values, | ||
default=np.nan) | ||
|
||
return np.array([np.nan]) | ||
|
||
def get_loc(self, key, method=None, tolerance=None): | ||
""" | ||
Get integer location for requested label | ||
|
Oops, something went wrong.
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.
this seems odd that you are returning np.nan for a datetimelike. do tests hit this?
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 would assume it does get hit indirectly as it was essentially pulled into the subclasses from the pd.Series instantiation. It is essentially replicating the behavior that was previously in lines 188-203 of pandas/core/series.py and allowing each object to handle it as seen fit rather than doing it in an if conditional. Personally this way make more sense to me but since I ended up not making use of this functionality outside of the Series instantiation I'm happy to revert the changes if you'd prefer.