@@ -1722,7 +1722,6 @@ def test_to_and_from_dataframe(self):
1722
1722
expected = Dataset ({'A' : DataArray ([], dims = ('index' ,))})
1723
1723
self .assertDatasetIdentical (expected , actual )
1724
1724
1725
-
1726
1725
# regression test for GH278
1727
1726
# use int64 to ensure consistent results for the pandas .equals method
1728
1727
# on windows (which requires the same dtype)
@@ -1741,12 +1740,37 @@ def test_to_and_from_dataframe(self):
1741
1740
expected = pd .DataFrame ([[]], index = idx )
1742
1741
assert expected .equals (actual ), (expected , actual )
1743
1742
1743
+ def test_from_dataframe_non_unique_columns (self ):
1744
1744
# regression test for GH449
1745
1745
df = pd .DataFrame (np .zeros ((2 , 2 )))
1746
1746
df .columns = ['foo' , 'foo' ]
1747
1747
with self .assertRaisesRegexp (ValueError , 'non-unique columns' ):
1748
1748
Dataset .from_dataframe (df )
1749
1749
1750
+ def test_convert_dataframe_with_many_types_and_multiindex (self ):
1751
+ # regression test for GH737
1752
+ df = pd .DataFrame ({'a' : list ('abc' ),
1753
+ 'b' : list (range (1 , 4 )),
1754
+ 'c' : np .arange (3 , 6 ).astype ('u1' ),
1755
+ 'd' : np .arange (4.0 , 7.0 , dtype = 'float64' ),
1756
+ 'e' : [True , False , True ],
1757
+ 'f' : pd .Categorical (list ('abc' )),
1758
+ 'g' : pd .date_range ('20130101' , periods = 3 ),
1759
+ 'h' : pd .date_range ('20130101' ,
1760
+ periods = 3 ,
1761
+ tz = 'US/Eastern' )})
1762
+ df .index = pd .MultiIndex .from_product ([['a' ], range (3 )],
1763
+ names = ['one' , 'two' ])
1764
+ roundtripped = Dataset .from_dataframe (df ).to_dataframe ()
1765
+ # we can't do perfectly, but we should be at least as faithful as
1766
+ # np.asarray
1767
+ expected = df .apply (np .asarray )
1768
+ if pd .__version__ < '0.17' :
1769
+ # datetime with timezone dtype is not consistent on old pandas
1770
+ roundtripped = roundtripped .drop (['h' ], axis = 1 )
1771
+ expected = expected .drop (['h' ], axis = 1 )
1772
+ assert roundtripped .equals (expected )
1773
+
1750
1774
def test_pickle (self ):
1751
1775
data = create_test_data ()
1752
1776
roundtripped = pickle .loads (pickle .dumps (data ))
0 commit comments