@@ -41,27 +41,33 @@ def test_union(self, tz, sort):
41
41
rng1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
42
42
other1 = pd .date_range ('1/6/2000' , freq = 'D' , periods = 5 , tz = tz )
43
43
expected1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 10 , tz = tz )
44
+ expected1_notsorted = pd .DatetimeIndex (list (other1 ) + list (rng1 ))
44
45
45
46
rng2 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
46
47
other2 = pd .date_range ('1/4/2000' , freq = 'D' , periods = 5 , tz = tz )
47
48
expected2 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 8 , tz = tz )
49
+ expected2_notsorted = pd .DatetimeIndex (list (other2 ) + list (rng2 [:3 ]))
48
50
49
51
rng3 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
50
52
other3 = pd .DatetimeIndex ([], tz = tz )
51
53
expected3 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
54
+ expected3_notsorted = rng3
52
55
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 )]:
56
62
57
63
result_union = rng .union (other , sort = sort )
58
- tm .assert_index_equal (result_union , expected )
64
+ tm .assert_index_equal (result_union , exp )
59
65
60
66
result_union = other .union (rng , sort = sort )
61
67
if sort is None :
62
- tm .assert_index_equal (result_union , expected )
68
+ tm .assert_index_equal (result_union , exp )
63
69
else :
64
- assert tm .equalContents (result_union , expected )
70
+ tm .assert_index_equal (result_union , exp_notsorted )
65
71
66
72
@pytest .mark .parametrize ("sort" , [None , False ])
67
73
def test_union_coverage (self , sort ):
@@ -96,7 +102,7 @@ def test_union_bug_1745(self, sort):
96
102
'2012-05-11 15:27:24.873000' ,
97
103
'2012-05-11 15:31:05.350000' ])
98
104
if sort is None :
99
- exp = DatetimeIndex ( sorted ( set ( list ( left )) | set ( list ( right ))) )
105
+ exp = exp . sort_values ( )
100
106
tm .assert_index_equal (result , exp )
101
107
102
108
@pytest .mark .parametrize ("sort" , [None , False ])
@@ -336,7 +342,8 @@ def test_union(self, sort):
336
342
if sort is None :
337
343
tm .assert_index_equal (right .union (left , sort = sort ), the_union )
338
344
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 )
340
347
341
348
# overlapping, but different offset
342
349
rng = date_range (START , END , freq = BMonthEnd ())
@@ -385,7 +392,8 @@ def test_union_not_cacheable(self, sort):
385
392
if sort is None :
386
393
tm .assert_index_equal (the_union , rng )
387
394
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 )
389
397
390
398
rng1 = rng [10 :]
391
399
rng2 = rng [15 :35 ]
0 commit comments