@@ -751,8 +751,7 @@ def test_union(self):
751
751
expected = Index (list ('ab' ), name = 'A' )
752
752
tm .assert_index_equal (union , expected )
753
753
754
- with tm .assert_produces_warning (RuntimeWarning ):
755
- firstCat = self .strIndex .union (self .dateIndex )
754
+ firstCat = self .strIndex .union (self .dateIndex )
756
755
secondCat = self .strIndex .union (self .strIndex )
757
756
758
757
if self .dateIndex .dtype == np .object_ :
@@ -1341,29 +1340,26 @@ def test_drop(self):
1341
1340
expected = Index ([1 , 2 ])
1342
1341
tm .assert_index_equal (dropped , expected )
1343
1342
1344
- def test_tuple_union_bug (self ):
1345
- import pandas
1346
- import numpy as np
1347
-
1343
+ def test_tuples_intersection_union (self ):
1348
1344
aidx1 = np .array ([(1 , 'A' ), (2 , 'A' ), (1 , 'B' ), (2 , 'B' )],
1349
1345
dtype = [('num' , int ), ('let' , 'a1' )])
1350
1346
aidx2 = np .array ([(1 , 'A' ), (2 , 'A' ), (1 , 'B' ),
1351
1347
(2 , 'B' ), (1 , 'C' ), (2 , 'C' )],
1352
1348
dtype = [('num' , int ), ('let' , 'a1' )])
1353
1349
1354
- idx1 = pandas . Index (aidx1 )
1355
- idx2 = pandas . Index (aidx2 )
1350
+ idx1 = Index (aidx1 )
1351
+ idx2 = Index (aidx2 )
1356
1352
1357
- # intersection broken?
1353
+ # intersection
1358
1354
int_idx = idx1 .intersection (idx2 )
1355
+ expected = idx1 # pandas.Index(sorted(set(idx1) & set(idx2)))
1359
1356
# needs to be 1d like idx1 and idx2
1360
- expected = idx1 [:4 ] # pandas.Index(sorted(set(idx1) & set(idx2)))
1361
1357
assert int_idx .ndim == 1
1362
1358
tm .assert_index_equal (int_idx , expected )
1363
1359
1364
- # union broken
1360
+ # GH 17376 (union)
1365
1361
union_idx = idx1 .union (idx2 )
1366
- expected = idx2
1362
+ expected = idx2 . sort_values ()
1367
1363
assert union_idx .ndim == 1
1368
1364
tm .assert_index_equal (union_idx , expected )
1369
1365
@@ -1553,13 +1549,19 @@ def test_outer_join_sort(self):
1553
1549
left_idx = Index (np .random .permutation (15 ))
1554
1550
right_idx = tm .makeDateIndex (10 )
1555
1551
1556
- with tm .assert_produces_warning (RuntimeWarning ):
1552
+ if PY3 :
1553
+ with tm .assert_produces_warning (RuntimeWarning ):
1554
+ joined = left_idx .join (right_idx , how = 'outer' )
1555
+ else :
1557
1556
joined = left_idx .join (right_idx , how = 'outer' )
1558
1557
1559
1558
# right_idx in this case because DatetimeIndex has join precedence over
1560
1559
# Int64Index
1561
- with tm .assert_produces_warning (RuntimeWarning ):
1562
- expected = right_idx .astype (object ).union (left_idx .astype (object ))
1560
+ if PY3 :
1561
+ with tm .assert_produces_warning (RuntimeWarning ):
1562
+ expected = right_idx .astype (object ).union (left_idx )
1563
+ else :
1564
+ expected = right_idx .astype (object ).union (left_idx )
1563
1565
tm .assert_index_equal (joined , expected )
1564
1566
1565
1567
def test_nan_first_take_datetime (self ):
@@ -1943,10 +1945,7 @@ def test_copy_name(self):
1943
1945
s1 = Series (2 , index = first )
1944
1946
s2 = Series (3 , index = second [:- 1 ])
1945
1947
1946
- warning_type = RuntimeWarning if PY3 else None
1947
- with tm .assert_produces_warning (warning_type ):
1948
- # Python 3: Unorderable types
1949
- s3 = s1 * s2
1948
+ s3 = s1 * s2
1950
1949
1951
1950
assert s3 .index .name == 'mario'
1952
1951
@@ -1979,27 +1978,14 @@ def test_union_base(self):
1979
1978
first = idx [3 :]
1980
1979
second = idx [:5 ]
1981
1980
1982
- if PY3 :
1983
- with tm .assert_produces_warning (RuntimeWarning ):
1984
- # unorderable types
1985
- result = first .union (second )
1986
- expected = Index (['b' , 2 , 'c' , 0 , 'a' , 1 ])
1987
- tm .assert_index_equal (result , expected )
1988
- else :
1989
- result = first .union (second )
1990
- expected = Index (['b' , 2 , 'c' , 0 , 'a' , 1 ])
1991
- tm .assert_index_equal (result , expected )
1981
+ expected = Index ([0 , 1 , 2 , 'a' , 'b' , 'c' ])
1982
+ result = first .union (second )
1983
+ tm .assert_index_equal (result , expected )
1992
1984
1993
1985
# GH 10149
1994
1986
cases = [klass (second .values )
1995
1987
for klass in [np .array , Series , list ]]
1996
1988
for case in cases :
1997
- if PY3 :
1998
- with tm .assert_produces_warning (RuntimeWarning ):
1999
- # unorderable types
2000
- result = first .union (case )
2001
- assert tm .equalContents (result , idx )
2002
- else :
2003
1989
result = first .union (case )
2004
1990
assert tm .equalContents (result , idx )
2005
1991
0 commit comments