Skip to content

Commit 22491dc

Browse files
authored
DOC: updated documentation for BusinessHour and BusinessDay (#50240)
* DOC: add examples to BusinessHour and BusinessDay I * DOC: add examples to BusinessHour and BusinessDay II * DOC: add examples to BusinessHour and BusinessDay III * DOC: add examples to BusinessHour and BusinessDay IV * DOC: add examples to BusinessHour and BusinessDay V * fixup! DOC: add examples to BusinessHour and BusinessDay V
1 parent e413b91 commit 22491dc

File tree

1 file changed

+60
-17
lines changed

1 file changed

+60
-17
lines changed

pandas/_libs/tslibs/offsets.pyx

+60-17
Original file line numberDiff line numberDiff line change
@@ -1494,11 +1494,29 @@ cdef class BusinessDay(BusinessMixin):
14941494
"""
14951495
DateOffset subclass representing possibly n business days.
14961496
1497+
Parameters
1498+
----------
1499+
n : int, default 1
1500+
The number of days represented.
1501+
normalize : bool, default False
1502+
Normalize start/end dates to midnight.
1503+
14971504
Examples
14981505
--------
1499-
>>> ts = pd.Timestamp(2022, 8, 5)
1500-
>>> ts + pd.offsets.BusinessDay()
1501-
Timestamp('2022-08-08 00:00:00')
1506+
You can use the parameter ``n`` to represent a shift of n business days.
1507+
1508+
>>> ts = pd.Timestamp(2022, 12, 9, 15)
1509+
>>> ts.strftime('%a %d %b %Y %H:%M')
1510+
'Fri 09 Dec 2022 15:00'
1511+
>>> (ts + pd.offsets.BusinessDay(n=5)).strftime('%a %d %b %Y %H:%M')
1512+
'Fri 16 Dec 2022 15:00'
1513+
1514+
Passing the parameter ``normalize`` equal to True, you shift the start
1515+
of the next business day to midnight.
1516+
1517+
>>> ts = pd.Timestamp(2022, 12, 9, 15)
1518+
>>> ts + pd.offsets.BusinessDay(normalize=True)
1519+
Timestamp('2022-12-12 00:00:00')
15021520
"""
15031521
_period_dtype_code = PeriodDtypeCode.B
15041522
_prefix = "B"
@@ -1610,29 +1628,53 @@ cdef class BusinessHour(BusinessMixin):
16101628
Parameters
16111629
----------
16121630
n : int, default 1
1613-
The number of months represented.
1631+
The number of hours represented.
16141632
normalize : bool, default False
16151633
Normalize start/end dates to midnight before generating date range.
1616-
weekmask : str, Default 'Mon Tue Wed Thu Fri'
1617-
Weekmask of valid business days, passed to ``numpy.busdaycalendar``.
16181634
start : str, time, or list of str/time, default "09:00"
16191635
Start time of your custom business hour in 24h format.
16201636
end : str, time, or list of str/time, default: "17:00"
16211637
End time of your custom business hour in 24h format.
16221638
16231639
Examples
16241640
--------
1625-
>>> from datetime import time
1641+
You can use the parameter ``n`` to represent a shift of n hours.
1642+
1643+
>>> ts = pd.Timestamp(2022, 12, 9, 8)
1644+
>>> ts + pd.offsets.BusinessHour(n=5)
1645+
Timestamp('2022-12-09 14:00:00')
1646+
1647+
You can also change the start and the end of business hours.
1648+
16261649
>>> ts = pd.Timestamp(2022, 8, 5, 16)
1627-
>>> ts + pd.offsets.BusinessHour()
1628-
Timestamp('2022-08-08 09:00:00')
16291650
>>> ts + pd.offsets.BusinessHour(start="11:00")
16301651
Timestamp('2022-08-08 11:00:00')
1631-
>>> ts + pd.offsets.BusinessHour(end=time(19, 0))
1632-
Timestamp('2022-08-05 17:00:00')
1633-
>>> ts + pd.offsets.BusinessHour(start=[time(9, 0), "20:00"],
1634-
... end=["17:00", time(22, 0)])
1635-
Timestamp('2022-08-05 20:00:00')
1652+
1653+
>>> from datetime import time as dt_time
1654+
>>> ts = pd.Timestamp(2022, 8, 5, 22)
1655+
>>> ts + pd.offsets.BusinessHour(end=dt_time(19, 0))
1656+
Timestamp('2022-08-08 10:00:00')
1657+
1658+
Passing the parameter ``normalize`` equal to True, you shift the start
1659+
of the next business hour to midnight.
1660+
1661+
>>> ts = pd.Timestamp(2022, 12, 9, 8)
1662+
>>> ts + pd.offsets.BusinessHour(normalize=True)
1663+
Timestamp('2022-12-09 00:00:00')
1664+
1665+
You can divide your business day hours into several parts.
1666+
1667+
>>> import datetime as dt
1668+
>>> freq = pd.offsets.BusinessHour(start=["06:00", "10:00", "15:00"],
1669+
... end=["08:00", "12:00", "17:00"])
1670+
>>> pd.date_range(dt.datetime(2022, 12, 9), dt.datetime(2022, 12, 13), freq=freq)
1671+
DatetimeIndex(['2022-12-09 06:00:00', '2022-12-09 07:00:00',
1672+
'2022-12-09 10:00:00', '2022-12-09 11:00:00',
1673+
'2022-12-09 15:00:00', '2022-12-09 16:00:00',
1674+
'2022-12-12 06:00:00', '2022-12-12 07:00:00',
1675+
'2022-12-12 10:00:00', '2022-12-12 11:00:00',
1676+
'2022-12-12 15:00:00', '2022-12-12 16:00:00'],
1677+
dtype='datetime64[ns]', freq='BH')
16361678
"""
16371679

16381680
_prefix = "BH"
@@ -3536,6 +3578,7 @@ cdef class CustomBusinessDay(BusinessDay):
35363578
Parameters
35373579
----------
35383580
n : int, default 1
3581+
The number of days represented.
35393582
normalize : bool, default False
35403583
Normalize start/end dates to midnight before generating date range.
35413584
weekmask : str, Default 'Mon Tue Wed Thu Fri'
@@ -3624,7 +3667,7 @@ cdef class CustomBusinessHour(BusinessHour):
36243667
Parameters
36253668
----------
36263669
n : int, default 1
3627-
The number of months represented.
3670+
The number of hours represented.
36283671
normalize : bool, default False
36293672
Normalize start/end dates to midnight before generating date range.
36303673
weekmask : str, Default 'Mon Tue Wed Thu Fri'
@@ -3662,7 +3705,7 @@ cdef class CustomBusinessHour(BusinessHour):
36623705
>>> ts + pd.offsets.CustomBusinessHour(end=dt_time(19, 0))
36633706
Timestamp('2022-08-08 10:00:00')
36643707
3665-
In the example below we divide our business day hours into several parts.
3708+
You can divide your business day hours into several parts.
36663709
36673710
>>> import datetime as dt
36683711
>>> freq = pd.offsets.CustomBusinessHour(start=["06:00", "10:00", "15:00"],
@@ -3692,7 +3735,7 @@ cdef class CustomBusinessHour(BusinessHour):
36923735
'Fri 16 Dec 2022 12:00'],
36933736
dtype='object')
36943737
3695-
In the example below we define custom holidays by using NumPy business day calendar.
3738+
Using NumPy business day calendar you can define custom holidays.
36963739
36973740
>>> import datetime as dt
36983741
>>> bdc = np.busdaycalendar(holidays=['2022-12-12', '2022-12-14'])

0 commit comments

Comments
 (0)