Skip to content

Commit 4092b34

Browse files
committed
updated comments
1 parent c690260 commit 4092b34

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

pandas/core/reshape/merge.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ def _restore_dropped_levels_multijoin(left, right, dropped_level_names,
11271127
"""
11281128
*this is an internal non-public method*
11291129
1130-
Returns the levels, labels and names of a multil-index to multi-index join.
1130+
Returns the levels, labels and names of a multi-index to multi-index join.
11311131
Depending on the type of join, this method restores the appropriate
11321132
dropped levels of the joined multi-index.
11331133
The method relies on lidx, rindexer which hold the index positions of
@@ -1140,13 +1140,13 @@ def _restore_dropped_levels_multijoin(left, right, dropped_level_names,
11401140
right : MultiIndex
11411141
right index
11421142
dropped_level_names : str array
1143-
list of non-common levels
1143+
list of non-common level names
11441144
join_index : MultiIndex
1145-
the index of the join between
1146-
the common levels of left and right
1145+
the index of the join between the
1146+
common levels of left and right
11471147
lindexer : intp array
11481148
left indexer
1149-
right : intp array
1149+
rindexer : intp array
11501150
right indexer
11511151
11521152
Returns
@@ -1160,21 +1160,29 @@ def _restore_dropped_levels_multijoin(left, right, dropped_level_names,
11601160
11611161
"""
11621162

1163-
# Convert to 1 level multi-index if not
1164-
if not isinstance(join_index, MultiIndex):
1165-
levels = [join_index.values]
1166-
labels = [list(range(join_index.size))]
1167-
names = [join_index.name]
1168-
join_index = MultiIndex(levels=levels, labels=labels,
1169-
names=names, verify_integrity=False)
1163+
def _convert_to_mulitindex(index):
1164+
if isinstance(index, MultiIndex):
1165+
return index
1166+
else:
1167+
levels = [index.values]
1168+
labels = [list(range(index.size))]
1169+
names = [index.name]
1170+
return MultiIndex(levels=levels, labels=labels, names=names,
1171+
verify_integrity=False)
1172+
1173+
# For multi-multi joins with one overlapping level,
1174+
# the returned index if of type Index
1175+
# Assure that join_index is of type MultiIndex
1176+
# so that dropped levels can be appended
1177+
join_index = _convert_to_mulitindex(join_index)
11701178

11711179
join_levels = join_index.levels
11721180
join_labels = join_index.labels
11731181
join_names = join_index.names
11741182

1175-
# lindexer and rindexer hold the indexes where the join occured
1176-
# for left and right respectively. If left (right) is None then
1177-
# the join occured on all indices of left (right)
1183+
# lindexer and rindexer hold the indexes where the join occurred
1184+
# for left and right respectively. If left/right is None then
1185+
# the join occurred on all indices of left/right
11781186
if lindexer is None:
11791187
lindexer = range(left.size)
11801188

0 commit comments

Comments
 (0)