Skip to content
Prev Previous commit
Next Next commit
BUG-24212 add comment
  • Loading branch information
JustinZhengBC committed Jan 24, 2019
commit a64b8fefcb6faeead50a95a6fe1e9d80a6841253
4 changes: 4 additions & 0 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ def _get_join_info(self):
join_index = self.left.index.take(left_indexer)
if (self.how == 'right' and -1 in left_indexer
and not isinstance(self.right.index, MultiIndex)):
# if values missing (-1) from left index,
# take from right index instead
join_list = join_index.to_numpy()
absent = left_indexer == -1
join_list[absent] = self.right.index.to_numpy()[absent]
Expand All @@ -773,6 +775,8 @@ def _get_join_info(self):
join_index = self.right.index.take(right_indexer)
if (self.how == 'left' and -1 in right_indexer
and not isinstance(self.left.index, MultiIndex)):
# if values missing (-1) from right index,
# take from left index instead
join_list = join_index.to_numpy()
absent = right_indexer == -1
join_list[absent] = self.left.index.to_numpy()[absent]
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/reshape/merge/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,8 @@ def test_merge_incompat_dtypes_error(self, df1_vals, df2_vals):
with pytest.raises(ValueError, match=msg):
pd.merge(df2, df1, on=['A'])

def test_merge_on_index_with_more_values(self): # GH 24212
def test_merge_on_index_with_more_values(self):
# GH 24212
df1 = pd.DataFrame([[1, 2], [2, 4], [3, 6], [4, 8]],
columns=['a', 'b'])
df2 = pd.DataFrame([[3, 30], [4, 40]],
Expand Down