Skip to content

DOC: updated documentation for BusinessHour and BusinessDay #50240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 17, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ cdef class BusinessHour(BusinessMixin):

Examples
--------
You can use the parameter ``n`` to represent the shift to n hours.
You can use the parameter ``n`` to represent a shift of n hours.

>>> ts = pd.Timestamp(2022, 12, 9, 8)
>>> ts + pd.offsets.BusinessHour(n=5)
Expand All @@ -1655,11 +1655,26 @@ cdef class BusinessHour(BusinessMixin):
>>> ts + pd.offsets.BusinessHour(end=dt_time(19, 0))
Timestamp('2022-08-08 10:00:00')

The parameter ``normalize`` equal True forces shift to midnight.
Passing the parameter ``normalize`` equal True, you shift the start
of next business hour to midnight.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above


>>> ts = pd.Timestamp(2022, 12, 9, 8)
>>> ts + pd.offsets.BusinessHour(normalize=True)
Timestamp('2022-12-09 00:00:00')

You can divide your business day hours into several parts.

>>> import datetime as dt
>>> freq = pd.offsets.CustomBusinessHour(start=["06:00", "10:00", "15:00"],
Copy link
Member

@MarcoGorelli MarcoGorelli Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should still be BusinessHour? Sorry, I meant "copy-and-paste but still change the offset", I should've clarified

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! I corrected my mistake. The copy-and-paste method can be dangerous sometimes.

... end=["08:00", "12:00", "17:00"])
>>> pd.date_range(dt.datetime(2022, 12, 9), dt.datetime(2022, 12, 13), freq=freq)
DatetimeIndex(['2022-12-09 06:00:00', '2022-12-09 07:00:00',
'2022-12-09 10:00:00', '2022-12-09 11:00:00',
'2022-12-09 15:00:00', '2022-12-09 16:00:00',
'2022-12-12 06:00:00', '2022-12-12 07:00:00',
'2022-12-12 10:00:00', '2022-12-12 11:00:00',
'2022-12-12 15:00:00', '2022-12-12 16:00:00'],
dtype='datetime64[ns]', freq='CBH')
"""

_prefix = "BH"
Expand Down