@@ -601,6 +601,42 @@ def test_excel_multindex_roundtrip(self):
601
601
header = list (range (c_idx_levels )))
602
602
tm .assert_frame_equal (df , act , check_names = check_names )
603
603
604
+ def test_excel_oldindex_format (self ):
605
+ #GH 4679
606
+ _skip_if_no_xlrd ()
607
+ data = np .array ([['R0C0' , 'R0C1' , 'R0C2' , 'R0C3' , 'R0C4' ],
608
+ ['R1C0' , 'R1C1' , 'R1C2' , 'R1C3' , 'R1C4' ],
609
+ ['R2C0' , 'R2C1' , 'R2C2' , 'R2C3' , 'R2C4' ],
610
+ ['R3C0' , 'R3C1' , 'R3C2' , 'R3C3' , 'R3C4' ],
611
+ ['R4C0' , 'R4C1' , 'R4C2' , 'R4C3' , 'R4C4' ]])
612
+ columns = ['C_l0_g0' , 'C_l0_g1' , 'C_l0_g2' , 'C_l0_g3' , 'C_l0_g4' ]
613
+ mi = MultiIndex (levels = [['R_l0_g0' , 'R_l0_g1' , 'R_l0_g2' , 'R_l0_g3' , 'R_l0_g4' ],
614
+ ['R_l1_g0' , 'R_l1_g1' , 'R_l1_g2' , 'R_l1_g3' , 'R_l1_g4' ]],
615
+ labels = [[0 , 1 , 2 , 3 , 4 ], [0 , 1 , 2 , 3 , 4 ]],
616
+ names = ['R0' , 'R1' ])
617
+ si = Index (['R_l0_g0' , 'R_l0_g1' , 'R_l0_g2' , 'R_l0_g3' , 'R_l0_g4' ], name = 'R0' )
618
+
619
+ in_file = os .path .join (self .dirpath , 'test_index_name_pre17.xlsx' )
620
+
621
+ expected = pd .DataFrame (data , index = si , columns = columns )
622
+ with tm .assert_produces_warning (FutureWarning ):
623
+ actual = pd .read_excel (in_file , 'single_names' , has_index_names = True )
624
+ tm .assert_frame_equal (actual , expected )
625
+
626
+ expected .index .name = None
627
+ actual = pd .read_excel (in_file , 'single_no_names' )
628
+ tm .assert_frame_equal (actual , expected )
629
+
630
+ expected .index = mi
631
+ with tm .assert_produces_warning (FutureWarning ):
632
+ actual = pd .read_excel (in_file , 'multi_names' , has_index_names = True )
633
+ tm .assert_frame_equal (actual , expected )
634
+
635
+ expected .index .names = [None , None ]
636
+ actual = pd .read_excel (in_file , 'multi_no_names' , index_col = [0 ,1 ])
637
+ tm .assert_frame_equal (actual , expected , check_names = False )
638
+
639
+
604
640
605
641
class XlsReaderTests (XlrdTests , tm .TestCase ):
606
642
ext = '.xls'
@@ -866,7 +902,6 @@ def test_roundtrip_indexlabels(self):
866
902
reader = ExcelFile (path )
867
903
recons = reader .parse ('test1' ,
868
904
index_col = 0 ,
869
- has_index_names = self .merge_cells
870
905
).astype (np .int64 )
871
906
frame .index .names = ['test' ]
872
907
self .assertEqual (frame .index .names , recons .index .names )
@@ -879,7 +914,6 @@ def test_roundtrip_indexlabels(self):
879
914
reader = ExcelFile (path )
880
915
recons = reader .parse ('test1' ,
881
916
index_col = 0 ,
882
- has_index_names = self .merge_cells
883
917
).astype (np .int64 )
884
918
frame .index .names = ['test' ]
885
919
self .assertEqual (frame .index .names , recons .index .names )
@@ -892,7 +926,6 @@ def test_roundtrip_indexlabels(self):
892
926
reader = ExcelFile (path )
893
927
recons = reader .parse ('test1' ,
894
928
index_col = 0 ,
895
- has_index_names = self .merge_cells
896
929
).astype (np .int64 )
897
930
frame .index .names = ['test' ]
898
931
tm .assert_frame_equal (frame , recons .astype (bool ))
@@ -922,8 +955,7 @@ def test_excel_roundtrip_indexname(self):
922
955
923
956
xf = ExcelFile (path )
924
957
result = xf .parse (xf .sheet_names [0 ],
925
- index_col = 0 ,
926
- has_index_names = self .merge_cells )
958
+ index_col = 0 )
927
959
928
960
tm .assert_frame_equal (result , df )
929
961
self .assertEqual (result .index .name , 'foo' )
@@ -1010,8 +1042,7 @@ def test_to_excel_multiindex(self):
1010
1042
frame .to_excel (path , 'test1' , merge_cells = self .merge_cells )
1011
1043
reader = ExcelFile (path )
1012
1044
df = reader .parse ('test1' , index_col = [0 , 1 ],
1013
- parse_dates = False ,
1014
- has_index_names = self .merge_cells )
1045
+ parse_dates = False )
1015
1046
tm .assert_frame_equal (frame , df )
1016
1047
self .assertEqual (frame .index .names , df .index .names )
1017
1048
@@ -1028,8 +1059,7 @@ def test_to_excel_multiindex_dates(self):
1028
1059
tsframe .to_excel (path , 'test1' , merge_cells = self .merge_cells )
1029
1060
reader = ExcelFile (path )
1030
1061
recons = reader .parse ('test1' ,
1031
- index_col = [0 , 1 ],
1032
- has_index_names = self .merge_cells )
1062
+ index_col = [0 , 1 ])
1033
1063
1034
1064
tm .assert_frame_equal (tsframe , recons )
1035
1065
self .assertEqual (recons .index .names , ('time' , 'foo' ))
0 commit comments