-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG-24212 fix regression in #24897 #24916
Changes from 8 commits
b04cee7
a64b8fe
022643d
e99dece
b95e1fe
73be0d0
de3e2c7
1287758
bdce7ac
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,22 @@ def _get_join_info(self): | |
|
||
if self.right_index: | ||
if len(self.left) > 0: | ||
join_index = self.left.index.take(left_indexer) | ||
print(left_indexer) | ||
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. extra print |
||
join_index = self._create_join_index(self.left.index, | ||
self.right.index, | ||
left_indexer, | ||
right_indexer, | ||
how='right') | ||
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(self.right.index, | ||
self.left.index, | ||
right_indexer, | ||
left_indexer, | ||
how='left') | ||
else: | ||
join_index = self.left.index.take(left_indexer) | ||
right_indexer = np.array([-1] * len(join_index)) | ||
|
@@ -774,6 +783,39 @@ def _get_join_info(self): | |
join_index = join_index.astype(object) | ||
return join_index, left_indexer, right_indexer | ||
|
||
def _create_join_index(self, index, other_index, indexer, | ||
other_indexer, how='left'): | ||
""" | ||
Create a join index by rearranging one index to match another | ||
|
||
Parameters | ||
---------- | ||
index: Index being rearranged | ||
other_index: Index used to supply values not found in index | ||
indexer: how to rearrange index | ||
how: replacement is only necessary if indexer based on other_index | ||
|
||
Returns | ||
------- | ||
join_index | ||
""" | ||
join_index = index.take(indexer) | ||
if (self.how in (how, 'outer') and | ||
not isinstance(other_index, MultiIndex)): | ||
# if final index requires values in other_index but not target | ||
# index, indexer may hold missing (-1) values, causing Index.take | ||
# to take the final value in target 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. Index.take has an argument to see -1 for missing value indicator, would that help here? (not sure not, as you are taking the value from the other index, but I don't fully understand why that is happening) 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. It is my understanding that |
||
mask = indexer == -1 | ||
if np.any(mask): | ||
# if values missing (-1) from target index, | ||
# take from other_index instead | ||
join_list = join_index.to_numpy() | ||
other_list = other_index.take(other_indexer).to_numpy() | ||
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. Why are we converting here to a numpy array? We should also test if this patch is working for such dtypes. |
||
join_list[mask] = other_list[mask] | ||
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.
Probably best for 0.24.1