Skip to content

Commit 925ce1b

Browse files
Update tests
1 parent 0e10a9d commit 925ce1b

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

pandas/io/tests/test_excel.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -887,17 +887,26 @@ def test_read_excel_chunksize(self):
887887
chunksize=100)
888888

889889
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
894891

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)
901910

902911
def test_read_excel_skiprows_list(self):
903912
# GH 4903
@@ -1339,8 +1348,7 @@ def test_to_excel_multiindex(self):
13391348
# round trip
13401349
frame.to_excel(path, 'test1', merge_cells=self.merge_cells)
13411350
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])
13441352
tm.assert_frame_equal(frame, df)
13451353

13461354
# GH13511
@@ -1381,8 +1389,7 @@ def test_to_excel_multiindex_cols(self):
13811389
frame.to_excel(path, 'test1', merge_cells=self.merge_cells)
13821390
reader = ExcelFile(path)
13831391
df = read_excel(reader, 'test1', header=header,
1384-
index_col=[0, 1],
1385-
parse_dates=False)
1392+
index_col=[0, 1])
13861393
if not self.merge_cells:
13871394
fm = frame.columns.format(sparsify=False,
13881395
adjoin=False, names=False)

0 commit comments

Comments
 (0)