@@ -750,8 +750,7 @@ def test_union(self):
750
750
expected = Index (list ('ab' ), name = 'A' )
751
751
tm .assert_index_equal (union , expected )
752
752
753
- with tm .assert_produces_warning (RuntimeWarning ):
754
- firstCat = self .strIndex .union (self .dateIndex )
753
+ firstCat = self .strIndex .union (self .dateIndex )
755
754
secondCat = self .strIndex .union (self .strIndex )
756
755
757
756
if self .dateIndex .dtype == np .object_ :
@@ -1309,29 +1308,26 @@ def test_drop(self):
1309
1308
expected = Index ([1 , 2 ])
1310
1309
tm .assert_index_equal (dropped , expected )
1311
1310
1312
- def test_tuple_union_bug (self ):
1313
- import pandas
1314
- import numpy as np
1315
-
1311
+ def test_tuples_intersection_union (self ):
1316
1312
aidx1 = np .array ([(1 , 'A' ), (2 , 'A' ), (1 , 'B' ), (2 , 'B' )],
1317
1313
dtype = [('num' , int ), ('let' , 'a1' )])
1318
1314
aidx2 = np .array ([(1 , 'A' ), (2 , 'A' ), (1 , 'B' ),
1319
1315
(2 , 'B' ), (1 , 'C' ), (2 , 'C' )],
1320
1316
dtype = [('num' , int ), ('let' , 'a1' )])
1321
1317
1322
- idx1 = pandas . Index (aidx1 )
1323
- idx2 = pandas . Index (aidx2 )
1318
+ idx1 = Index (aidx1 )
1319
+ idx2 = Index (aidx2 )
1324
1320
1325
- # intersection broken?
1321
+ # intersection
1326
1322
int_idx = idx1 .intersection (idx2 )
1323
+ expected = idx1 # pandas.Index(sorted(set(idx1) & set(idx2)))
1327
1324
# needs to be 1d like idx1 and idx2
1328
- expected = idx1 [:4 ] # pandas.Index(sorted(set(idx1) & set(idx2)))
1329
1325
assert int_idx .ndim == 1
1330
1326
tm .assert_index_equal (int_idx , expected )
1331
1327
1332
- # union broken
1328
+ # GH 17376 (union)
1333
1329
union_idx = idx1 .union (idx2 )
1334
- expected = idx2
1330
+ expected = idx2 . sort_values ()
1335
1331
assert union_idx .ndim == 1
1336
1332
tm .assert_index_equal (union_idx , expected )
1337
1333
@@ -1507,13 +1503,19 @@ def test_outer_join_sort(self):
1507
1503
left_idx = Index (np .random .permutation (15 ))
1508
1504
right_idx = tm .makeDateIndex (10 )
1509
1505
1510
- with tm .assert_produces_warning (RuntimeWarning ):
1506
+ if PY3 :
1507
+ with tm .assert_produces_warning (RuntimeWarning ):
1508
+ joined = left_idx .join (right_idx , how = 'outer' )
1509
+ else :
1511
1510
joined = left_idx .join (right_idx , how = 'outer' )
1512
1511
1513
1512
# right_idx in this case because DatetimeIndex has join precedence over
1514
1513
# Int64Index
1515
- with tm .assert_produces_warning (RuntimeWarning ):
1516
- expected = right_idx .astype (object ).union (left_idx .astype (object ))
1514
+ if PY3 :
1515
+ with tm .assert_produces_warning (RuntimeWarning ):
1516
+ expected = right_idx .astype (object ).union (left_idx )
1517
+ else :
1518
+ expected = right_idx .astype (object ).union (left_idx )
1517
1519
tm .assert_index_equal (joined , expected )
1518
1520
1519
1521
def test_nan_first_take_datetime (self ):
@@ -1897,10 +1899,7 @@ def test_copy_name(self):
1897
1899
s1 = Series (2 , index = first )
1898
1900
s2 = Series (3 , index = second [:- 1 ])
1899
1901
1900
- warning_type = RuntimeWarning if PY3 else None
1901
- with tm .assert_produces_warning (warning_type ):
1902
- # Python 3: Unorderable types
1903
- s3 = s1 * s2
1902
+ s3 = s1 * s2
1904
1903
1905
1904
assert s3 .index .name == 'mario'
1906
1905
@@ -1933,27 +1932,14 @@ def test_union_base(self):
1933
1932
first = idx [3 :]
1934
1933
second = idx [:5 ]
1935
1934
1936
- if PY3 :
1937
- with tm .assert_produces_warning (RuntimeWarning ):
1938
- # unorderable types
1939
- result = first .union (second )
1940
- expected = Index (['b' , 2 , 'c' , 0 , 'a' , 1 ])
1941
- tm .assert_index_equal (result , expected )
1942
- else :
1943
- result = first .union (second )
1944
- expected = Index (['b' , 2 , 'c' , 0 , 'a' , 1 ])
1945
- tm .assert_index_equal (result , expected )
1935
+ expected = Index ([0 , 1 , 2 , 'a' , 'b' , 'c' ])
1936
+ result = first .union (second )
1937
+ tm .assert_index_equal (result , expected )
1946
1938
1947
1939
# GH 10149
1948
1940
cases = [klass (second .values )
1949
1941
for klass in [np .array , Series , list ]]
1950
1942
for case in cases :
1951
- if PY3 :
1952
- with tm .assert_produces_warning (RuntimeWarning ):
1953
- # unorderable types
1954
- result = first .union (case )
1955
- assert tm .equalContents (result , idx )
1956
- else :
1957
1943
result = first .union (case )
1958
1944
assert tm .equalContents (result , idx )
1959
1945
0 commit comments