@@ -41,27 +41,33 @@ def test_union(self, tz, sort):
4141        rng1  =  pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
4242        other1  =  pd .date_range ('1/6/2000' , freq = 'D' , periods = 5 , tz = tz )
4343        expected1  =  pd .date_range ('1/1/2000' , freq = 'D' , periods = 10 , tz = tz )
44+         expected1_notsorted  =  pd .DatetimeIndex (list (other1 ) +  list (rng1 ))
4445
4546        rng2  =  pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
4647        other2  =  pd .date_range ('1/4/2000' , freq = 'D' , periods = 5 , tz = tz )
4748        expected2  =  pd .date_range ('1/1/2000' , freq = 'D' , periods = 8 , tz = tz )
49+         expected2_notsorted  =  pd .DatetimeIndex (list (other2 ) +  list (rng2 [:3 ]))
4850
4951        rng3  =  pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
5052        other3  =  pd .DatetimeIndex ([], tz = tz )
5153        expected3  =  pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
54+         expected3_notsorted  =  rng3 
5255
53-         for  rng , other , expected  in  [(rng1 , other1 , expected1 ),
54-                                      (rng2 , other2 , expected2 ),
55-                                      (rng3 , other3 , expected3 )]:
56+         for  rng , other , exp , exp_notsorted  in  [(rng1 , other1 , expected1 ,
57+                                                 expected1_notsorted ),
58+                                                (rng2 , other2 , expected2 ,
59+                                                 expected2_notsorted ),
60+                                                (rng3 , other3 , expected3 ,
61+                                                 expected3_notsorted )]:
5662
5763            result_union  =  rng .union (other , sort = sort )
58-             tm .assert_index_equal (result_union , expected )
64+             tm .assert_index_equal (result_union , exp )
5965
6066            result_union  =  other .union (rng , sort = sort )
6167            if  sort  is  None :
62-                 tm .assert_index_equal (result_union , expected )
68+                 tm .assert_index_equal (result_union , exp )
6369            else :
64-                 assert   tm .equalContents (result_union , expected )
70+                 tm .assert_index_equal (result_union , exp_notsorted )
6571
6672    @pytest .mark .parametrize ("sort" , [None , False ]) 
6773    def  test_union_coverage (self , sort ):
@@ -96,7 +102,7 @@ def test_union_bug_1745(self, sort):
96102                             '2012-05-11 15:27:24.873000' ,
97103                             '2012-05-11 15:31:05.350000' ])
98104        if  sort  is  None :
99-             exp  =  DatetimeIndex ( sorted ( set ( list ( left ))  |   set ( list ( right ))) )
105+             exp  =  exp . sort_values ( )
100106        tm .assert_index_equal (result , exp )
101107
102108    @pytest .mark .parametrize ("sort" , [None , False ]) 
@@ -336,7 +342,8 @@ def test_union(self, sort):
336342        if  sort  is  None :
337343            tm .assert_index_equal (right .union (left , sort = sort ), the_union )
338344        else :
339-             assert  tm .equalContents (right .union (left , sort = sort ), the_union )
345+             expected  =  pd .DatetimeIndex (list (right ) +  list (left ))
346+             tm .assert_index_equal (right .union (left , sort = sort ), expected )
340347
341348        # overlapping, but different offset 
342349        rng  =  date_range (START , END , freq = BMonthEnd ())
@@ -385,7 +392,8 @@ def test_union_not_cacheable(self, sort):
385392        if  sort  is  None :
386393            tm .assert_index_equal (the_union , rng )
387394        else :
388-             assert  tm .equalContents (the_union , rng )
395+             expected  =  pd .DatetimeIndex (list (rng [10 :]) +  list (rng [:10 ]))
396+             tm .assert_index_equal (the_union , expected )
389397
390398        rng1  =  rng [10 :]
391399        rng2  =  rng [15 :35 ]
0 commit comments