-
-
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
Merged
MarcoGorelli
merged 6 commits into
pandas-dev:main
from
natmokval:doc-businesshour-businessday
Dec 17, 2022
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
71cae1d
DOC: add examples to BusinessHour and BusinessDay I
natmokval 7aa4747
DOC: add examples to BusinessHour and BusinessDay II
natmokval 573eaec
DOC: add examples to BusinessHour and BusinessDay III
natmokval 23222a2
DOC: add examples to BusinessHour and BusinessDay IV
natmokval b16dab7
DOC: add examples to BusinessHour and BusinessDay V
natmokval 61e8555
fixup! DOC: add examples to BusinessHour and BusinessDay V
natmokval File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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 represent a shift of n business 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. | ||
|
||
>>> 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.BusinessHour(start=["06:00", "10:00", "15:00"], | ||
... 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='BH') | ||
""" | ||
|
||
_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']) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.