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
62 changes: 45 additions & 17 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1494,11 +1494,29 @@ cdef class BusinessDay(BusinessMixin):
"""
DateOffset subclass representing possibly n business days.

Parameters
----------
n : int, default 1
The number of days represented.
normalize : bool, default False
Normalize start/end dates to midnight before generating date range.

Examples
--------
>>> ts = pd.Timestamp(2022, 8, 5)
>>> ts + pd.offsets.BusinessDay()
Timestamp('2022-08-08 00:00:00')
You can use the parameter ``n`` to shift the next business day to n days.

>>> ts = pd.Timestamp(2022, 12, 9, 15)
>>> ts.strftime('%a %d %b %Y %H:%M')
'Fri 09 Dec 2022 15:00'
>>> (ts + pd.offsets.BusinessDay(n=5)).strftime('%a %d %b %Y %H:%M')
'Fri 16 Dec 2022 15:00'

Passing the parameter ``normalize`` equal True, you shift the start
of next business day 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.

equal True -> equal to True

of next business day -> of the next business day

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I corrected my grammar mistakes and updated my PR.


>>> ts = pd.Timestamp(2022, 12, 9, 15)
>>> ts + pd.offsets.BusinessDay(normalize=True)
Timestamp('2022-12-12 00:00:00')
"""
_period_dtype_code = PeriodDtypeCode.B
_prefix = "B"
Expand Down Expand Up @@ -1610,29 +1628,38 @@ cdef class BusinessHour(BusinessMixin):
Parameters
----------
n : int, default 1
The number of months represented.
The number of hours represented.
normalize : bool, default False
Normalize start/end dates to midnight before generating date range.
weekmask : str, Default 'Mon Tue Wed Thu Fri'
Weekmask of valid business days, passed to ``numpy.busdaycalendar``.
start : str, time, or list of str/time, default "09:00"
Start time of your custom business hour in 24h format.
end : str, time, or list of str/time, default: "17:00"
End time of your custom business hour in 24h format.

Examples
--------
>>> from datetime import time
You can use the parameter ``n`` to represent the shift to n hours.
Copy link
Member

Choose a reason for hiding this comment

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

perhaps "to represent a shift of n hours" would be clearer? likewise for above


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

You can also change the start and the end of business hours.

>>> ts = pd.Timestamp(2022, 8, 5, 16)
>>> ts + pd.offsets.BusinessHour()
Timestamp('2022-08-08 09:00:00')
>>> ts + pd.offsets.BusinessHour(start="11:00")
Timestamp('2022-08-08 11:00:00')
>>> ts + pd.offsets.BusinessHour(end=time(19, 0))
Timestamp('2022-08-05 17:00:00')
>>> ts + pd.offsets.BusinessHour(start=[time(9, 0), "20:00"],
... end=["17:00", time(22, 0)])
Timestamp('2022-08-05 20:00:00')

>>> from datetime import time as dt_time
>>> ts = pd.Timestamp(2022, 8, 5, 22)
>>> 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.
Copy link
Member

Choose a reason for hiding this comment

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

I think it's clearer how you wrote it above

Passing the parameter ``normalize`` equal True, you shift the start
of next business hour to midnight.


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

_prefix = "BH"
Expand Down Expand Up @@ -3536,6 +3563,7 @@ cdef class CustomBusinessDay(BusinessDay):
Parameters
----------
n : int, default 1
The number of days represented.
normalize : bool, default False
Normalize start/end dates to midnight before generating date range.
weekmask : str, Default 'Mon Tue Wed Thu Fri'
Expand Down Expand Up @@ -3624,7 +3652,7 @@ cdef class CustomBusinessHour(BusinessHour):
Parameters
----------
n : int, default 1
The number of months represented.
The number of hours represented.
normalize : bool, default False
Normalize start/end dates to midnight before generating date range.
weekmask : str, Default 'Mon Tue Wed Thu Fri'
Expand Down Expand Up @@ -3662,7 +3690,7 @@ cdef class CustomBusinessHour(BusinessHour):
>>> ts + pd.offsets.CustomBusinessHour(end=dt_time(19, 0))
Timestamp('2022-08-08 10:00:00')

In the example below we divide our business day hours into several parts.
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"],
Expand Down Expand Up @@ -3692,7 +3720,7 @@ cdef class CustomBusinessHour(BusinessHour):
'Fri 16 Dec 2022 12:00'],
dtype='object')

In the example below we define custom holidays by using NumPy business day calendar.
Using NumPy business day calendar you can define custom holidays.

>>> import datetime as dt
>>> bdc = np.busdaycalendar(holidays=['2022-12-12', '2022-12-14'])
Expand Down