Skip to content

Commit 45ffeeb

Browse files
committed
FIX-#2442: fixed condition to compute indexers
Signed-off-by: Dmitry Chigarev <[email protected]>
1 parent 1c6b258 commit 45ffeeb

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

modin/engines/base/frame/data.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,22 +1002,24 @@ def merge(left_index, right_index):
10021002
return left_index.join(right_index, how=how, sort=sort)
10031003

10041004
# define condition for joining indexes
1005-
do_join_index = how is not None and any(
1006-
not indexes[0].equals(index) for index in [indexes[1:]]
1007-
)
1005+
all_indices_equal = all(indexes[0].equals(index) for index in [indexes[1:]])
1006+
do_join_index = how is not None and not all_indices_equal
10081007

10091008
# define condition for joining indexes with getting indexers
1010-
is_duplicates = axis == 0 and any(not index.is_unique for index in indexes)
1011-
indexers = []
1012-
if is_duplicates:
1013-
indexers = [None] * len(indexes)
1009+
need_indexers = (
1010+
axis == 0
1011+
and not all_indices_equal
1012+
and any(not index.is_unique for index in indexes)
1013+
)
1014+
indexers = None
10141015

10151016
# perform joining indexes
10161017
if do_join_index:
1017-
if len(indexes) == 2 and is_duplicates:
1018+
if len(indexes) == 2 and need_indexers:
10181019
# in case of count of indexes > 2 we should perform joining all indexes
10191020
# after that get indexers
10201021
# in the fast path we can obtain joined_index and indexers in one call
1022+
indexers = [None, None]
10211023
joined_index, indexers[0], indexers[1] = indexes[0].join(
10221024
indexes[1], how=how, sort=sort, return_indexers=True
10231025
)
@@ -1029,17 +1031,16 @@ def merge(left_index, right_index):
10291031
else:
10301032
joined_index = indexes[0].copy()
10311033

1032-
if is_duplicates and indexers[0] is None:
1033-
for i, index in enumerate(indexes):
1034-
indexers[i] = index.get_indexer_for(joined_index)
1034+
if need_indexers and indexers is None:
1035+
indexers = [index.get_indexer_for(joined_index) for index in indexes]
10351036

10361037
def make_reindexer(do_reindex: bool, frame_idx: int):
10371038
# the order of the frames must match the order of the indexes
10381039
if not do_reindex:
10391040
return lambda df: df
10401041

1041-
if is_duplicates:
1042-
assert indexers != []
1042+
if need_indexers:
1043+
assert indexers is not None
10431044

10441045
return lambda df: df._reindex_with_indexers(
10451046
{0: [joined_index, indexers[frame_idx]]},

0 commit comments

Comments
 (0)