@@ -667,6 +667,7 @@ def assert_index_equal(
667
667
check_less_precise : Union [bool , int ] = no_default ,
668
668
check_exact : bool = True ,
669
669
check_categorical : bool = True ,
670
+ check_order : bool = True ,
670
671
rtol : float = 1.0e-5 ,
671
672
atol : float = 1.0e-8 ,
672
673
obj : str = "Index" ,
@@ -696,6 +697,10 @@ def assert_index_equal(
696
697
Whether to compare number exactly.
697
698
check_categorical : bool, default True
698
699
Whether to compare internal Categorical exactly.
700
+ check_order : bool, default True
701
+ Whether to compare the order of index entries as well as their values.
702
+ If True, both indexes must contain the same elements, in the same order.
703
+ If False, both indexes must contain the same elements, but in any order.
699
704
rtol : float, default 1e-5
700
705
Relative tolerance. Only used when check_exact is False.
701
706
@@ -762,6 +767,11 @@ def _get_ilevel_values(index, level):
762
767
msg3 = f"{ len (right )} , { right } "
763
768
raise_assert_detail (obj , msg1 , msg2 , msg3 )
764
769
770
+ # If order doesn't matter then sort the index entries
771
+ if not check_order :
772
+ left = left .sort_values ()
773
+ right = right .sort_values ()
774
+
765
775
# MultiIndex special comparison for little-friendly error messages
766
776
if left .nlevels > 1 :
767
777
left = cast (MultiIndex , left )
@@ -1582,9 +1592,6 @@ def assert_frame_equal(
1582
1592
obj , f"{ obj } shape mismatch" , f"{ repr (left .shape )} " , f"{ repr (right .shape )} "
1583
1593
)
1584
1594
1585
- if check_like :
1586
- left , right = left .reindex_like (right ), right
1587
-
1588
1595
if check_flags :
1589
1596
assert left .flags == right .flags , f"{ repr (left .flags )} != { repr (right .flags )} "
1590
1597
@@ -1596,6 +1603,7 @@ def assert_frame_equal(
1596
1603
check_names = check_names ,
1597
1604
check_exact = check_exact ,
1598
1605
check_categorical = check_categorical ,
1606
+ check_order = not check_like ,
1599
1607
rtol = rtol ,
1600
1608
atol = atol ,
1601
1609
obj = f"{ obj } .index" ,
@@ -1609,11 +1617,15 @@ def assert_frame_equal(
1609
1617
check_names = check_names ,
1610
1618
check_exact = check_exact ,
1611
1619
check_categorical = check_categorical ,
1620
+ check_order = not check_like ,
1612
1621
rtol = rtol ,
1613
1622
atol = atol ,
1614
1623
obj = f"{ obj } .columns" ,
1615
1624
)
1616
1625
1626
+ if check_like :
1627
+ left , right = left .reindex_like (right ), right
1628
+
1617
1629
# compare by blocks
1618
1630
if by_blocks :
1619
1631
rblocks = right ._to_dict_of_blocks ()
0 commit comments