-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG-24212 fix usage of Index.take in pd.merge #24733
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
Changes from 4 commits
7c83e55
9777041
d81b596
d72427a
9e49ff6
cc5d83c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -757,13 +757,15 @@ def _get_join_info(self): | |
|
||
if self.right_index: | ||
if len(self.left) > 0: | ||
join_index = self.left.index.take(left_indexer) | ||
join_index = self._create_join_index(left_indexer, | ||
using_left=True) | ||
else: | ||
join_index = self.right.index.take(right_indexer) | ||
left_indexer = np.array([-1] * len(join_index)) | ||
elif self.left_index: | ||
if len(self.right) > 0: | ||
join_index = self.right.index.take(right_indexer) | ||
join_index = self._create_join_index(right_indexer, | ||
using_left=False) | ||
else: | ||
join_index = self.left.index.take(left_indexer) | ||
right_indexer = np.array([-1] * len(join_index)) | ||
|
@@ -774,6 +776,28 @@ def _get_join_info(self): | |
join_index = join_index.astype(object) | ||
return join_index, left_indexer, right_indexer | ||
|
||
def _create_join_index(self, indexer, using_left=True): | ||
if using_left: | ||
index = self.left.index | ||
other_index = self.right.index | ||
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. maybe to make this more clear, pass |
||
how_check = 'right' | ||
else: | ||
index = self.right.index | ||
other_index = self.left.index | ||
how_check = 'left' | ||
|
||
join_index = index.take(indexer) | ||
if self.how == how_check and not isinstance(other_index, MultiIndex): | ||
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. add a comment here on what you are doing |
||
absent = indexer == -1 | ||
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. absent -> mask |
||
if any(absent): | ||
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. use |
||
# if values missing (-1) from target index, | ||
# take from other index instead | ||
join_list = join_index.to_numpy() | ||
join_list[absent] = other_index.to_numpy()[absent] | ||
join_index = Index(join_list, dtype=join_index.dtype, | ||
name=join_index.name) | ||
return join_index | ||
|
||
def _get_merge_keys(self): | ||
""" | ||
Note: has side effects (copy/delete key columns) | ||
|
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.
can you add a doc-string