@@ -3619,6 +3619,8 @@ cdef class CustomBusinessHour(BusinessHour):
3619
3619
"""
3620
3620
DateOffset subclass representing possibly n custom business days.
3621
3621
3622
+ In CustomBusinessHour we can use custom weekmask, holidays, and calendar.
3623
+
3622
3624
Parameters
3623
3625
----------
3624
3626
n : int, default 1
@@ -3627,24 +3629,81 @@ cdef class CustomBusinessHour(BusinessHour):
3627
3629
Normalize start/end dates to midnight before generating date range.
3628
3630
weekmask : str, Default 'Mon Tue Wed Thu Fri'
3629
3631
Weekmask of valid business days, passed to ``numpy.busdaycalendar``.
3632
+ holidays : list
3633
+ List/array of dates to exclude from the set of valid business days,
3634
+ passed to ``numpy.busdaycalendar``.
3635
+ calendar : np.busdaycalendar
3636
+ Calendar to integrate.
3630
3637
start : str, time, or list of str/time, default "09:00"
3631
3638
Start time of your custom business hour in 24h format.
3632
3639
end : str, time, or list of str/time, default: "17:00"
3633
3640
End time of your custom business hour in 24h format.
3634
3641
3635
3642
Examples
3636
3643
--------
3637
- >>> from datetime import time
3644
+ In the example below the default parameters give the next business hour.
3645
+
3638
3646
>>> ts = pd.Timestamp(2022, 8, 5, 16)
3639
3647
>>> ts + pd.offsets.CustomBusinessHour()
3640
3648
Timestamp('2022-08-08 09:00:00')
3649
+
3650
+ We can also change the start and the end of business hours.
3651
+
3652
+ >>> ts = pd.Timestamp(2022, 8, 5, 16)
3641
3653
>>> ts + pd.offsets.CustomBusinessHour(start="11:00")
3642
3654
Timestamp('2022-08-08 11:00:00')
3643
- >>> ts + pd.offsets.CustomBusinessHour(end=time(19, 0))
3655
+
3656
+ >>> from datetime import time as dt_time
3657
+ >>> ts = pd.Timestamp(2022, 8, 5, 16)
3658
+ >>> ts + pd.offsets.CustomBusinessHour(end=dt_time(19, 0))
3644
3659
Timestamp('2022-08-05 17:00:00')
3645
- >>> ts + pd.offsets.CustomBusinessHour(start=[time(9, 0), "20:00"],
3646
- ... end=["17:00", time(22, 0)])
3647
- Timestamp('2022-08-05 20:00:00')
3660
+
3661
+ >>> ts = pd.Timestamp(2022, 8, 5, 22)
3662
+ >>> ts + pd.offsets.CustomBusinessHour(end=dt_time(19, 0))
3663
+ Timestamp('2022-08-08 10:00:00')
3664
+
3665
+ In the example below we divide our business day hours into several parts.
3666
+
3667
+ >>> import datetime as dt
3668
+ >>> freq = pd.offsets.CustomBusinessHour(start=["06:00", "10:00", "15:00"],
3669
+ ... end=["08:00", "12:00", "17:00"])
3670
+ >>> pd.date_range(dt.datetime(2022, 12, 9), dt.datetime(2022, 12, 13), freq=freq)
3671
+ DatetimeIndex(['2022-12-09 06:00:00', '2022-12-09 07:00:00',
3672
+ '2022-12-09 10:00:00', '2022-12-09 11:00:00',
3673
+ '2022-12-09 15:00:00', '2022-12-09 16:00:00',
3674
+ '2022-12-12 06:00:00', '2022-12-12 07:00:00',
3675
+ '2022-12-12 10:00:00', '2022-12-12 11:00:00',
3676
+ '2022-12-12 15:00:00', '2022-12-12 16:00:00'],
3677
+ dtype='datetime64[ns]', freq='CBH')
3678
+
3679
+ Business days can be specified by ``weekmask`` parameter. To convert
3680
+ the returned datetime object to its string representation
3681
+ the function strftime() is used in the next example.
3682
+
3683
+ >>> import datetime as dt
3684
+ >>> freq = pd.offsets.CustomBusinessHour(weekmask="Mon Wed Fri",
3685
+ ... start="10:00", end="13:00")
3686
+ >>> pd.date_range(dt.datetime(2022, 12, 10), dt.datetime(2022, 12, 18),
3687
+ ... freq=freq).strftime('%a %d %b %Y %H :%M ')
3688
+ Index(['Mon 12 Dec 2022 10:00', 'Mon 12 Dec 2022 11:00',
3689
+ 'Mon 12 Dec 2022 12:00', 'Wed 14 Dec 2022 10:00',
3690
+ 'Wed 14 Dec 2022 11:00', 'Wed 14 Dec 2022 12:00',
3691
+ 'Fri 16 Dec 2022 10:00', 'Fri 16 Dec 2022 11:00',
3692
+ 'Fri 16 Dec 2022 12:00'],
3693
+ dtype='object')
3694
+
3695
+ In the example below we define custom holidays by using NumPy business day calendar.
3696
+
3697
+ >>> import datetime as dt
3698
+ >>> bdc = np.busdaycalendar(holidays=['2022-12-12', '2022-12-14'])
3699
+ >>> freq = pd.offsets.CustomBusinessHour(calendar=bdc, start="10:00", end="13:00")
3700
+ >>> pd.date_range(dt.datetime(2022, 12, 10), dt.datetime(2022, 12, 18), freq=freq)
3701
+ DatetimeIndex(['2022-12-13 10:00:00', '2022-12-13 11:00:00',
3702
+ '2022-12-13 12:00:00', '2022-12-15 10:00:00',
3703
+ '2022-12-15 11:00:00', '2022-12-15 12:00:00',
3704
+ '2022-12-16 10:00:00', '2022-12-16 11:00:00',
3705
+ '2022-12-16 12:00:00'],
3706
+ dtype='datetime64[ns]', freq='CBH')
3648
3707
"""
3649
3708
3650
3709
_prefix = " CBH"
0 commit comments