@@ -1348,6 +1348,40 @@ def test_format_sparse_config(self):
13481348
13491349 warnings .filters = warn_filters
13501350
1351+ def test_to_dataframe (self ):
1352+ tuples = [(1 , 'one' ), (1 , 'two' ), (2 , 'one' ), (2 , 'two' )]
1353+
1354+ index = MultiIndex .from_tuples (tuples )
1355+ result = index .to_dataframe (index = False )
1356+ expected = DataFrame (tuples )
1357+ tm .assert_frame_equal (result , expected )
1358+
1359+ result = index .to_dataframe ()
1360+ expected .index = index
1361+ tm .assert_frame_equal (result , expected )
1362+
1363+ tuples = [(1 , 'one' ), (1 , 'two' ), (2 , 'one' ), (2 , 'two' )]
1364+ index = MultiIndex .from_tuples (tuples , names = ['first' , 'second' ])
1365+ result = index .to_dataframe (index = False )
1366+ expected = DataFrame (tuples )
1367+ expected .columns = ['first' , 'second' ]
1368+ tm .assert_frame_equal (result , expected )
1369+
1370+ result = index .to_dataframe ()
1371+ expected .index = index
1372+ tm .assert_frame_equal (result , expected )
1373+
1374+ index = MultiIndex .from_product ([range (5 ), pd .date_range ('20130101' , periods = 3 )])
1375+ result = index .to_dataframe (index = False )
1376+ expected = DataFrame ({0 : np .repeat (np .arange (5 , dtype = 'int64' ), 3 ),
1377+ 1 : np .tile (pd .date_range ('20130101' , periods = 3 ), 5 )})
1378+ tm .assert_frame_equal (result , expected )
1379+
1380+ index = MultiIndex .from_product ([range (5 ), pd .date_range ('20130101' , periods = 3 )])
1381+ result = index .to_dataframe ()
1382+ expected .index = index
1383+ tm .assert_frame_equal (result , expected )
1384+
13511385 def test_to_hierarchical (self ):
13521386 index = MultiIndex .from_tuples ([(1 , 'one' ), (1 , 'two' ), (2 , 'one' ), (
13531387 2 , 'two' )])
0 commit comments