Skip to content

Commit 8d381f4

Browse files
committed
BUG: Fix Xl(sx|wt)Writer always using date_format.
Since `datetime.datetime` derives from `datetime.date` the second `if`-clause will always trigger, leading to the `num_format_str` being overwritten by the `date_format`.
1 parent f851b57 commit 8d381f4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ Bug Fixes
478478
- Bug in ``Float64Index.isin()`` where containing ``nan`` s would make indices
479479
claim that they contained all the things (:issue:`7066`).
480480
- Bug in ``DataFrame.boxplot`` where it failed to use the axis passed as the ``ax`` argument (:issue:`3578`)
481+
- Bug in the ``XlsxWriter`` and ``XlwtWriter`` implementations that resulted in datetime columns being formatted without the time (:issue:`7075`)
481482

482483
pandas 0.13.1
483484
-------------

pandas/io/excel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def write_cells(self, cells, sheet_name=None, startrow=0, startcol=0):
661661
num_format_str = None
662662
if isinstance(cell.val, datetime.datetime):
663663
num_format_str = self.datetime_format
664-
if isinstance(cell.val, datetime.date):
664+
elif isinstance(cell.val, datetime.date):
665665
num_format_str = self.date_format
666666

667667
stylekey = json.dumps(cell.style)
@@ -782,7 +782,7 @@ def write_cells(self, cells, sheet_name=None, startrow=0, startcol=0):
782782
num_format_str = None
783783
if isinstance(cell.val, datetime.datetime):
784784
num_format_str = self.datetime_format
785-
if isinstance(cell.val, datetime.date):
785+
elif isinstance(cell.val, datetime.date):
786786
num_format_str = self.date_format
787787

788788
stylekey = json.dumps(cell.style)

0 commit comments

Comments
 (0)