Skip to content

Commit 9851b36

Browse files
author
Sylvain MARIE
committed
Performance improvement in :meth:Series.to_excel and :meth:DataFrame.to_excel (:class:ExcelFormatter): processing dates can be up to 4% faster. (related to :issue:44764)
1 parent f6e4e5a commit 9851b36

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ Performance improvements
387387
- Performance improvement in :class:`DataFrame` and :class:`Series` constructors for extension dtype scalars (:issue:`45854`)
388388
- Performance improvement in :class:`BusinessHour`, ``str`` and ``repr`` are now 4 times faster ! (related to :issue:`44764`)
389389
- Performance improvement in :class:`DatetimeArray` and :class:`DatetimeIndex`: string formatting is now up to 80% faster (as fast as default) when one of the default strftime formats ``"%Y-%m-%d %H:%M:%S"`` or ``"%Y-%m-%d %H:%M:%S.%f"`` is used. (:issue:`44764`)
390+
- Performance improvement in :meth:`Series.to_excel` and :meth:`DataFrame.to_excel` (:class:`ExcelFormatter`): processing dates can be up to 4% faster. (related to :issue:`44764`)
390391

391392
.. ---------------------------------------------------------------------------
392393
.. _whatsnew_150.bug_fixes:

pandas/io/excel/_odswriter.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ def _make_table_cell(self, cell) -> tuple[object, Any]:
189189
value = str(val).lower()
190190
pvalue = str(val).upper()
191191
if isinstance(val, datetime.datetime):
192-
value = val.isoformat()
193-
pvalue = val.strftime("%c")
192+
value = val.isoformat() # fast formatting
193+
pvalue = val.strftime("%c") # slow but locale-dependent
194194
return (
195195
pvalue,
196196
TableCell(valuetype="date", datevalue=value, attributes=attributes),
197197
)
198198
elif isinstance(val, datetime.date):
199-
value = val.strftime("%Y-%m-%d")
200-
pvalue = val.strftime("%x")
199+
value = f"{val.year}-{val.month:02d}-{val.day:02d}" # fast formatting
200+
pvalue = val.strftime("%x") # slow but locale-dependent
201201
return (
202202
pvalue,
203203
TableCell(valuetype="date", datevalue=value, attributes=attributes),

0 commit comments

Comments
 (0)