@@ -278,32 +278,34 @@ def _merge_index_list(index_list,
278
278
duplicate values. This is error is not raised if
279
279
allow_matching_dups=True and all the indexes have a common identity.
280
280
"""
281
- if verify_dups or sort :
282
- has_dups = any (ix .has_duplicates for ix in index_list )
283
-
284
- if sort and has_dups :
285
- raise _CannotSortDuplicatesError ("Cannot sort an index that"
286
- " contains duplicate values." )
287
-
288
- if has_dups and not allow_matching_dups :
289
- raise _DuplicatesError ("Index has duplicate values." )
290
-
291
- uindex_list = com .get_distinct_objs (index_list ) # unique index list
281
+ # unique index list (a is b)
282
+ uindex_list = com .get_distinct_objs (index_list )
283
+
284
+ # verify duplicates
285
+ if sort or verify_dups :
286
+ has_dups = any (ix .has_duplicates for ix in uindex_list )
287
+ if has_dups :
288
+ if sort :
289
+ raise _CannotSortDuplicatesError ("Cannot sort an index that"
290
+ " contains duplicate values." )
291
+ elif verify_dups and not allow_matching_dups :
292
+ raise _DuplicatesError ("Index has duplicate values." )
293
+ elif verify_dups and allow_matching_dups and len (uindex_list ) >= 2 :
294
+ raise _DuplicatesError ("Index has duplicate values and does"
295
+ " not match other indexes." )
296
+
297
+ # edge results
292
298
if len (uindex_list ) == 0 :
293
299
return pd .Index ()
294
300
elif len (uindex_list ) == 1 :
295
301
return uindex_list [0 ]
296
302
297
- # index_list has at least two indexes
298
- if has_dups :
299
- raise _DuplicatesError ("Index has duplicate values and does"
300
- " not match other indexes." )
301
-
302
- # index_list has no indexes with duplicates
303
+ # reduce to one result
303
304
result = uindex_list [0 ]
304
305
for idx in uindex_list [1 :]:
305
306
result = _merge_indexes (result , idx )
306
307
308
+ # sort
307
309
return result if not sort else _sort_index (result )
308
310
309
311
0 commit comments