8000 BUG-24212 fix when other_index has incompatible dtype by JustinZhengBC · Pull Request #25009 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG-24212 fix when other_index has incompatible dtype #25009

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 30 commits into from
May 5, 2019
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b04cee7
BUG-24212 fix usage of Index.take in pd.merge
JustinZhengBC Jan 11, 2019
a64b8fe
BUG-24212 add comment
JustinZhengBC Jan 11, 2019
022643d
BUG-24212 clarify test
JustinZhengBC Jan 12, 2019
e99dece
BUG-24212 make _create_join_index function
JustinZhengBC Jan 14, 2019
b95e1fe
BUG-24212 add docstring and comments
JustinZhengBC Jan 17, 2019
73be0d0
BUG-24212 fix regression
JustinZhengBC Jan 24, 2019
de3e2c7
BUG-24212 alter old test
JustinZhengBC Jan 24, 2019
1287758
fix typo
JustinZhengBC Jan 24, 2019
bdce7ac
BUG-24212 remove print and move whatsnew note
JustinZhengBC Jan 24, 2019
83ae393
BUG-24212 fix when other_index has incompatible dtype
JustinZhengBC Jan 29, 2019
4cb3ab0
Merge branch 'master' into BUG-24212
JustinZhengBC Jan 29, 2019
66f6fe4
merge issue
JustinZhengBC Jan 29, 2019
cf6fa14
fix whatsnew
JustinZhengBC Jan 29, 2019
0e6de81
BUG-24212 fix test
JustinZhengBC Jan 29, 2019
1da789a
BUG-24212 fix test
JustinZhengBC Jan 29, 2019
a0e5ffc
Merge branch 'BUG-24212' of https://github.com/justinzhengbc/pandas i…
JustinZhengBC Jan 29, 2019
27cdbc8
BUG-24212 simplify take logic
JustinZhengBC Jan 31, 2019
cd326b2
fix import order
JustinZhengBC Jan 31, 2019
2c65ebf
Merge branch 'master' into BUG-24212
JustinZhengBC Mar 26, 2019
d8d3cdf
make logic more generic
JustinZhengBC Mar 26, 2019
f9e7386
make logic more generic
JustinZhengBC Mar 26, 2019
8a36130
Merge branch 'BUG-24212' of https://github.com/justinzhengbc/pandas i…
JustinZhengBC Mar 27, 2019
7da3655
clean up test
JustinZhengBC Mar 29, 2019
17c5497
use compat=False for na_value_for_dtype
JustinZhengBC Mar 29, 2019
720dfbb
Merge branch 'master' into BUG-24212
JustinZhengBC Apr 21, 2019
6772618
clarify whatsnew
JustinZhengBC Apr 22, 2019
dacb4bc
Merge branch 'master' into BUG-24212
JustinZhengBC Apr 22, 2019
cad4398
add PR number to whatsnew
JustinZhengBC Apr 22, 2019
5e2eb0f
Merge branch 'BUG-24212' of https://github.com/justinzhengbc/pandas i…
JustinZhengBC Apr 22, 2019
88cdf8b
Merge branch 'master' into BUG-24212
JustinZhengBC Apr 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BUG-24212 make _create_join_index function
  • Loading branch information
JustinZhengBC committed Jan 24, 2019
commit e99dece04119c989f6f5327300062a14afc4dc35
47 changes: 26 additions & 21 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,32 +757,15 @@ def _get_join_info(self):

if self.right_index:
if len(self.left) > 0:
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]
join_index = Index(join_list, dtype=join_index.dtype,
name=join_index.name)
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)
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
print(right_indexer)
join_list = join_index.to_numpy()
absent = right_indexer == -1
join_list[absent] = self.left.index.to_numpy()[absent]
join_index = Index(join_list, dtype=join_index.dtype,
name=join_index.name)
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))
Expand All @@ -793,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
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):
absent = indexer == -1
if any(absent):
# 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)
Expand Down
0