@@ -1127,7 +1127,7 @@ def _restore_dropped_levels_multijoin(left, right, dropped_level_names,
1127
1127
"""
1128
1128
*this is an internal non-public method*
1129
1129
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.
1131
1131
Depending on the type of join, this method restores the appropriate
1132
1132
dropped levels of the joined multi-index.
1133
1133
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,
1140
1140
right : MultiIndex
1141
1141
right index
1142
1142
dropped_level_names : str array
1143
- list of non-common levels
1143
+ list of non-common level names
1144
1144
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
1147
1147
lindexer : intp array
1148
1148
left indexer
1149
- right : intp array
1149
+ rindexer : intp array
1150
1150
right indexer
1151
1151
1152
1152
Returns
@@ -1160,21 +1160,29 @@ def _restore_dropped_levels_multijoin(left, right, dropped_level_names,
1160
1160
1161
1161
"""
1162
1162
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 )
1170
1178
1171
1179
join_levels = join_index .levels
1172
1180
join_labels = join_index .labels
1173
1181
join_names = join_index .names
1174
1182
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
1178
1186
if lindexer is None :
1179
1187
lindexer = range (left .size )
1180
1188
0 commit comments