@@ -1657,11 +1657,73 @@ def test_handle_empty_objects(self):
1657
1657
# GH3259
1658
1658
df = DataFrame (dict (A = range (10000 )),index = date_range ('20130101' ,periods = 10000 ,freq = 's' ))
1659
1659
empty = DataFrame ()
1660
+ result = concat ([df ,empty ],axis = 1 )
1661
+ assert_frame_equal (result , df )
1662
+ result = concat ([empty ,df ],axis = 1 )
1663
+ assert_frame_equal (result , df )
1664
+
1660
1665
result = concat ([df ,empty ])
1661
1666
assert_frame_equal (result , df )
1662
1667
result = concat ([empty ,df ])
1663
1668
assert_frame_equal (result , df )
1664
1669
1670
+ def test_concat_mixed_objs (self ):
1671
+
1672
+ # concat mixed series/frames
1673
+ # G2385
1674
+
1675
+ # axis 1
1676
+ index = date_range ('01-Jan-2013' , periods = 10 , freq = 'H' )
1677
+ arr = np .arange (10 , dtype = 'int64' )
1678
+ s1 = Series (arr , index = index )
1679
+ s2 = Series (arr , index = index )
1680
+ df = DataFrame (arr .reshape (- 1 ,1 ), index = index )
1681
+
1682
+ expected = DataFrame (np .repeat (arr ,2 ).reshape (- 1 ,2 ), index = index , columns = [0 , 0 ])
1683
+ result = concat ([df ,df ], axis = 1 )
1684
+ assert_frame_equal (result , expected )
1685
+
1686
+ expected = DataFrame (np .repeat (arr ,2 ).reshape (- 1 ,2 ), index = index , columns = [0 , 1 ])
1687
+ result = concat ([s1 ,s2 ], axis = 1 )
1688
+ assert_frame_equal (result , expected )
1689
+
1690
+ expected = DataFrame (np .repeat (arr ,3 ).reshape (- 1 ,3 ), index = index , columns = [0 , 1 , 2 ])
1691
+ result = concat ([s1 ,s2 ,s1 ], axis = 1 )
1692
+ assert_frame_equal (result , expected )
1693
+
1694
+ expected = DataFrame (np .repeat (arr ,5 ).reshape (- 1 ,5 ), index = index , columns = [0 , 0 , 1 , 2 , 3 ])
1695
+ result = concat ([s1 ,df ,s2 ,s2 ,s1 ], axis = 1 )
1696
+ assert_frame_equal (result , expected )
1697
+
1698
+ # with names
1699
+ s1 .name = 'foo'
1700
+ expected = DataFrame (np .repeat (arr ,3 ).reshape (- 1 ,3 ), index = index , columns = ['foo' , 0 , 0 ])
1701
+ result = concat ([s1 ,df ,s2 ], axis = 1 )
1702
+ assert_frame_equal (result , expected )
1703
+
1704
+ s2 .name = 'bar'
1705
+ expected = DataFrame (np .repeat (arr ,3 ).reshape (- 1 ,3 ), index = index , columns = ['foo' , 0 , 'bar' ])
1706
+ result = concat ([s1 ,df ,s2 ], axis = 1 )
1707
+ assert_frame_equal (result , expected )
1708
+
1709
+ # ignore index
1710
+ expected = DataFrame (np .repeat (arr ,3 ).reshape (- 1 ,3 ), index = index , columns = [0 , 1 , 2 ])
1711
+ result = concat ([s1 ,df ,s2 ], axis = 1 , ignore_index = True )
1712
+ assert_frame_equal (result , expected )
1713
+
1714
+ # axis 0
1715
+ expected = DataFrame (np .tile (arr ,3 ).reshape (- 1 ,1 ), index = index .tolist () * 3 , columns = [0 ])
1716
+ result = concat ([s1 ,df ,s2 ])
1717
+ assert_frame_equal (result , expected )
1718
+
1719
+ expected = DataFrame (np .tile (arr ,3 ).reshape (- 1 ,1 ), columns = [0 ])
1720
+ result = concat ([s1 ,df ,s2 ], ignore_index = True )
1721
+ assert_frame_equal (result , expected )
1722
+
1723
+ # invalid concatente of mixed dims
1724
+ panel = tm .makePanel ()
1725
+ self .assertRaises (ValueError , lambda : concat ([panel ,s1 ],axis = 1 ))
1726
+
1665
1727
def test_panel_join (self ):
1666
1728
panel = tm .makePanel ()
1667
1729
tm .add_nans (panel )
@@ -1991,15 +2053,6 @@ def test_concat_invalid_first_argument(self):
1991
2053
# generator ok though
1992
2054
concat (DataFrame (np .random .rand (5 ,5 )) for _ in range (3 ))
1993
2055
1994
- def test_concat_mixed_types_fails (self ):
1995
- df = DataFrame (randn (10 , 1 ))
1996
-
1997
- with tm .assertRaisesRegexp (TypeError , "Cannot concatenate.+" ):
1998
- concat ([df [0 ], df ], axis = 1 )
1999
-
2000
- with tm .assertRaisesRegexp (TypeError , "Cannot concatenate.+" ):
2001
- concat ([df , df [0 ]], axis = 1 )
2002
-
2003
2056
class TestOrderedMerge (tm .TestCase ):
2004
2057
2005
2058
def setUp (self ):
0 commit comments