-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 2 commits
71cae1d
7aa4747
573eaec
23222a2
b16dab7
61e8555
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
>>> 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
@@ -1610,29 +1628,53 @@ 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``. | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 a shift of n hours. | ||
|
||
>>> 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)]) | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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') | ||
|
||
Passing the parameter ``normalize`` equal True, you shift the start | ||
of next business hour to midnight. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this should still be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
@@ -3536,6 +3578,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' | ||
|
@@ -3624,7 +3667,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' | ||
|
@@ -3662,7 +3705,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. | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
>>> import datetime as dt | ||
>>> freq = pd.offsets.CustomBusinessHour(start=["06:00", "10:00", "15:00"], | ||
|
@@ -3692,7 +3735,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']) | ||
|
Uh oh!
There was an error while loading. Please reload this page.