Skip to content

Commit 01b9667

Browse files
author
Sylvain MARIE
committed
Performance improvement in :class:BusinessHour, repr is now 4 times faster ! Related to pandas-dev#44764
1 parent dbc3afa commit 01b9667

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ 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`)
388389

389390
.. ---------------------------------------------------------------------------
390391
.. _whatsnew_150.bug_fixes:

pandas/_libs/tslibs/offsets.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1566,8 +1566,10 @@ cdef class BusinessHour(BusinessMixin):
15661566

15671567
def _repr_attrs(self) -> str:
15681568
out = super()._repr_attrs()
1569+
# Use python string formatting to be faster than strftime
1570+
# f'{st.strftime("%H:%M")}-{en.strftime("%H:%M")}'
15691571
hours = ",".join(
1570-
f'{st.strftime("%H:%M")}-{en.strftime("%H:%M")}'
1572+
f'{st.hour:02d}:{st.minute:02d}-{en.hour:02d}:{en.minute:02d}'
15711573
for st, en in zip(self.start, self.end)
15721574
)
15731575
attrs = [f"{self._prefix}={hours}"]

0 commit comments

Comments
 (0)