@@ -887,17 +887,26 @@ def test_read_excel_chunksize(self):
887
887
chunksize = 100 )
888
888
889
889
def test_read_excel_parse_dates (self ):
890
- # GH 11544
891
- with tm .assertRaises (NotImplementedError ):
892
- pd .read_excel (os .path .join (self .dirpath , 'test1' + self .ext ),
893
- parse_dates = True )
890
+ # GH 11544, 12051
894
891
895
- def test_read_excel_date_parser (self ):
896
- # GH 11544
897
- with tm .assertRaises (NotImplementedError ):
898
- dateparse = lambda x : pd .datetime .strptime (x , '%Y-%m-%d %H:%M:%S' )
899
- pd .read_excel (os .path .join (self .dirpath , 'test1' + self .ext ),
900
- date_parser = dateparse )
892
+ df = DataFrame ({'col' : [1 , 2 , 3 ],
893
+ 'date_strings' : pd .date_range ('2012-01-01' , periods = 3 )})
894
+ df2 = df .copy ()
895
+ df2 ['date_strings' ] = df2 ['date_strings' ].dt .strftime ('%m/%d/%Y' )
896
+
897
+ with ensure_clean (self .ext ) as pth :
898
+ df2 .to_excel (pth )
899
+
900
+ res = read_excel (pth )
901
+ tm .assert_frame_equal (df2 , res )
902
+
903
+ res = read_excel (pth , parse_dates = ['date_strings' ])
904
+ tm .assert_frame_equal (df , res )
905
+
906
+ dateparser = lambda x : pd .datetime .strptime (x , '%m/%d/%Y' )
907
+ res = read_excel (pth , parse_dates = ['date_strings' ],
908
+ date_parser = dateparser )
909
+ tm .assert_frame_equal (df , res )
901
910
902
911
def test_read_excel_skiprows_list (self ):
903
912
# GH 4903
@@ -1339,8 +1348,7 @@ def test_to_excel_multiindex(self):
1339
1348
# round trip
1340
1349
frame .to_excel (path , 'test1' , merge_cells = self .merge_cells )
1341
1350
reader = ExcelFile (path )
1342
- df = read_excel (reader , 'test1' , index_col = [0 , 1 ],
1343
- parse_dates = False )
1351
+ df = read_excel (reader , 'test1' , index_col = [0 , 1 ])
1344
1352
tm .assert_frame_equal (frame , df )
1345
1353
1346
1354
# GH13511
@@ -1381,8 +1389,7 @@ def test_to_excel_multiindex_cols(self):
1381
1389
frame .to_excel (path , 'test1' , merge_cells = self .merge_cells )
1382
1390
reader = ExcelFile (path )
1383
1391
df = read_excel (reader , 'test1' , header = header ,
1384
- index_col = [0 , 1 ],
1385
- parse_dates = False )
1392
+ index_col = [0 , 1 ])
1386
1393
if not self .merge_cells :
1387
1394
fm = frame .columns .format (sparsify = False ,
1388
1395
adjoin = False , names = False )
0 commit comments