Skip to content

Commit 903d08c

Browse files
author
Sylvain MARIE
committed
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. See pandas-dev#44764
1 parent cdffff8 commit 903d08c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

doc/source/whatsnew/v1.5.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ Performance improvements
385385
- Performance improvement when setting values in a pyarrow backed string array (:issue:`46400`)
386386
- Performance improvement in :func:`factorize` (:issue:`46109`)
387387
- Performance improvement in :class:`DataFrame` and :class:`Series` constructors for extension dtype scalars (:issue:`45854`)
388-
- Performance improvement in :class:`BusinessHour`, ``repr`` is now 4 times faster ! (related to :issue:`44764`)
388+
- Performance improvement in :class:`BusinessHour`, ``str`` and ``repr`` are now 4 times faster ! (related to :issue:`44764`)
389+
- 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`)
389390

390391
.. ---------------------------------------------------------------------------
391392
.. _whatsnew_150.bug_fixes:

pandas/_libs/tslib.pyx

+10
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ def format_array_from_datetime(
145145
consider_values //= 1000
146146
show_ms = (consider_values % 1000).any()
147147

148+
elif format == "%Y-%m-%d %H:%M:%S":
149+
# Same format as default, but with hardcoded precision (s)
150+
basic_format = True
151+
show_ns = show_us = show_ms = False
152+
153+
elif format == "%Y-%m-%d %H:%M:%S.%f":
154+
# Same format as default, but with hardcoded precision (us)
155+
basic_format = show_us = True
156+
show_ns = show_ms = False
157+
148158
for i in range(N):
149159
val = values[i]
150160

0 commit comments

Comments
 (0)