Skip to content

Commit 9723e49

Browse files
committed
TST: Fix date/datetime format test (GH44284)
Swap rows and columns so that columns are homogenous and dates aren't converted to datetimes (i.e. datetime64[ns]) on initialisation of df. Clarify scope of test.
1 parent 086e6f9 commit 9723e49

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

pandas/tests/io/excel/test_writers.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -652,25 +652,27 @@ def test_excel_roundtrip_datetime(self, merge_cells, tsframe, path):
652652

653653
tm.assert_frame_equal(tsframe, recons)
654654

655-
def test_excel_date_datetime_format(self, ext, path):
655+
def test_excel_roundtrip_date_datetime_format(self, ext, path):
656656
# see gh-4133
657657
#
658-
# Excel output format strings
658+
# Test that df written with custom date/datetime format strings
659+
# is read back the same as if written using the default formats,
660+
# and that the values are still recognised as dates/datetimes.
659661
df = DataFrame(
660662
[
661-
[date(2014, 1, 31), date(1999, 9, 24)],
662-
[datetime(1998, 5, 26, 23, 33, 4), datetime(2014, 2, 28, 13, 5, 13)],
663+
[date(2014, 1, 31), datetime(1998, 5, 26, 23, 33, 4)],
664+
[date(1999, 9, 24), datetime(2014, 2, 28, 13, 5, 13)],
663665
],
664-
index=["DATE", "DATETIME"],
665-
columns=["X", "Y"],
666+
index=["X", "Y"],
667+
columns=["DATE", "DATETIME"],
666668
)
667669
df_expected = DataFrame(
668670
[
669-
[datetime(2014, 1, 31), datetime(1999, 9, 24)],
670-
[datetime(1998, 5, 26, 23, 33, 4), datetime(2014, 2, 28, 13, 5, 13)],
671+
[datetime(2014, 1, 31), datetime(1998, 5, 26, 23, 33, 4)],
672+
[datetime(1999, 9, 24), datetime(2014, 2, 28, 13, 5, 13)],
671673
],
672-
index=["DATE", "DATETIME"],
673-
columns=["X", "Y"],
674+
index=["X", "Y"],
675+
columns=["DATE", "DATETIME"],
674676
)
675677

676678
with tm.ensure_clean(ext) as filename2:

0 commit comments

Comments
 (0)