Skip to content

Commit

Permalink
Performance improvement in :class:BusinessHour, repr is now 4 t…
Browse files Browse the repository at this point in the history
…imes faster ! Related to pandas-dev#44764
  • Loading branch information
Sylvain MARIE committed Apr 12, 2022
1 parent dbc3afa commit 01b9667
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Expand Up @@ -385,6 +385,7 @@ Performance improvements
- Performance improvement when setting values in a pyarrow backed string array (:issue:`46400`)
- Performance improvement in :func:`factorize` (:issue:`46109`)
- Performance improvement in :class:`DataFrame` and :class:`Series` constructors for extension dtype scalars (:issue:`45854`)
- Performance improvement in :class:`BusinessHour`, ``repr`` is now 4 times faster ! (related to :issue:`44764`)

.. ---------------------------------------------------------------------------
.. _whatsnew_150.bug_fixes:
Expand Down
4 changes: 3 additions & 1 deletion pandas/_libs/tslibs/offsets.pyx
Expand Up @@ -1566,8 +1566,10 @@ cdef class BusinessHour(BusinessMixin):

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

0 comments on commit 01b9667

Please sign in to comment.