|
6 | 6 | import random
|
7 | 7 |
|
8 | 8 | from pandas import *
|
9 |
| -from pandas.tools.merge import merge |
| 9 | +from pandas.tools.merge import merge, concat |
10 | 10 | from pandas.util.testing import (assert_frame_equal, assert_series_equal,
|
11 | 11 | assert_almost_equal, rands)
|
12 | 12 | import pandas._tseries as lib
|
@@ -741,6 +741,40 @@ def test_append_missing_column_proper_upcast(self):
|
741 | 741 | self.assert_(appended['A'].dtype == 'f8')
|
742 | 742 | self.assert_(appended['B'].dtype == 'O')
|
743 | 743 |
|
| 744 | + def test_crossed_dtypes_weird_corner(self): |
| 745 | + columns = ['A', 'B', 'C', 'D'] |
| 746 | + df1 = DataFrame({'A' : np.array([1, 2, 3, 4], dtype='f8'), |
| 747 | + 'B' : np.array([1, 2, 3, 4], dtype='i8'), |
| 748 | + 'C' : np.array([1, 2, 3, 4], dtype='f8'), |
| 749 | + 'D' : np.array([1, 2, 3, 4], dtype='i8')}, |
| 750 | + columns=columns) |
| 751 | + |
| 752 | + df2 = DataFrame({'A' : np.array([1, 2, 3, 4], dtype='i8'), |
| 753 | + 'B' : np.array([1, 2, 3, 4], dtype='f8'), |
| 754 | + 'C' : np.array([1, 2, 3, 4], dtype='i8'), |
| 755 | + 'D' : np.array([1, 2, 3, 4], dtype='f8')}, |
| 756 | + columns=columns) |
| 757 | + |
| 758 | + appended = df1.append(df2, ignore_index=True) |
| 759 | + expected = DataFrame(np.concatenate([df1.values, df2.values], axis=0), |
| 760 | + columns=columns) |
| 761 | + tm.assert_frame_equal(appended, expected) |
| 762 | + |
| 763 | + def test_handle_empty_objects(self): |
| 764 | + df = DataFrame(np.random.randn(10, 4), columns=list('abcd')) |
| 765 | + |
| 766 | + baz = df[:5] |
| 767 | + baz['foo'] = 'bar' |
| 768 | + empty = df[5:5] |
| 769 | + |
| 770 | + frames = [baz, empty, empty, df[5:]] |
| 771 | + concatted = concat(frames, axis=0) |
| 772 | + |
| 773 | + expected = df.ix[:, ['a', 'b', 'c', 'd', 'foo']] |
| 774 | + expected['foo'] = expected['foo'].astype('O') |
| 775 | + expected['foo'][:5] = 'bar' |
| 776 | + |
| 777 | + tm.assert_frame_equal(concatted, expected) |
744 | 778 |
|
745 | 779 | def test_panel_join(self):
|
746 | 780 | panel = tm.makePanel()
|
@@ -800,10 +834,23 @@ def test_panel_join_many(self):
|
800 | 834 | joined = panels[0].join(panels[1:])
|
801 | 835 | tm.assert_panel_equal(joined, panel)
|
802 | 836 |
|
| 837 | + panels = [panel.ix[:2, :-5], panel.ix[2:6, 2:], panel.ix[6:, 5:-7]] |
| 838 | + |
| 839 | + data_dict = {} |
| 840 | + for p in panels: |
| 841 | + data_dict.update(p.iterkv()) |
| 842 | + |
| 843 | + joined = panels[0].join(panels[1:], how='inner') |
| 844 | + expected = Panel.from_dict(data_dict, intersect=True) |
| 845 | + tm.assert_panel_equal(joined, expected) |
| 846 | + |
| 847 | + joined = panels[0].join(panels[1:], how='outer') |
| 848 | + expected = Panel.from_dict(data_dict, intersect=False) |
| 849 | + tm.assert_panel_equal(joined, expected) |
| 850 | + |
803 | 851 | if __name__ == '__main__':
|
804 | 852 | import nose
|
805 | 853 | nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
|
806 | 854 | exit=False)
|
807 | 855 |
|
808 | 856 |
|
809 |
| - |
|
0 commit comments