@@ -2574,11 +2574,28 @@ cdef class MonthBegin(MonthOffset):
2574
2574
"""
2575
2575
DateOffset of one month at beginning.
2576
2576
2577
+ MonthBegin goes to the next date which is a start of the month.
2578
+ To get the start of the current month pass the parameter n equals 0.
2579
+
2580
+ See Also
2581
+ --------
2582
+ :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
2583
+
2577
2584
Examples
2578
2585
--------
2579
- >>> ts = pd.Timestamp(2022, 1, 1)
2586
+ >>> ts = pd.Timestamp(2022, 11, 30)
2587
+ >>> ts + pd.offsets.MonthBegin()
2588
+ Timestamp('2022-12-01 00:00:00')
2589
+
2590
+ >>> ts = pd.Timestamp(2022, 12, 1)
2580
2591
>>> ts + pd.offsets.MonthBegin()
2581
- Timestamp('2022-02-01 00:00:00')
2592
+ Timestamp('2023-01-01 00:00:00')
2593
+
2594
+ If you want to get the start of the current month pass the parameter n equals 0:
2595
+
2596
+ >>> ts = pd.Timestamp(2022, 12, 1)
2597
+ >>> ts + pd.offsets.MonthBegin(0)
2598
+ Timestamp('2022-12-01 00:00:00')
2582
2599
"""
2583
2600
_prefix = " MS"
2584
2601
_day_opt = " start"
@@ -2616,16 +2633,26 @@ cdef class BusinessMonthBegin(MonthOffset):
2616
2633
"""
2617
2634
DateOffset of one month at the first business day.
2618
2635
2636
+ BusinessMonthBegin goes to the next date which is the first business day
2637
+ of the month. To get the first business day of the current month pass
2638
+ the parameter n equals 0.
2639
+
2619
2640
Examples
2620
2641
--------
2621
- >>> from pandas.tseries.offsets import BMonthBegin
2622
- >>> ts=pd.Timestamp('2020-05-24 05:01:15')
2623
- >>> ts + BMonthBegin()
2624
- Timestamp('2020-06-01 05:01:15')
2625
- >>> ts + BMonthBegin(2)
2626
- Timestamp('2020-07-01 05:01:15')
2627
- >>> ts + BMonthBegin(-3)
2628
- Timestamp('2020-03-02 05:01:15')
2642
+ >>> ts = pd.Timestamp(2022, 11, 30)
2643
+ >>> ts + pd.offsets.BMonthBegin()
2644
+ Timestamp('2022-12-01 00:00:00')
2645
+
2646
+ >>> ts = pd.Timestamp(2022, 12, 1)
2647
+ >>> ts + pd.offsets.BMonthBegin()
2648
+ Timestamp('2023-01-02 00:00:00')
2649
+
2650
+ If you want to get the start of the current business month pass
2651
+ the parameter n equals 0:
2652
+
2653
+ >>> ts = pd.Timestamp(2022, 12, 1)
2654
+ >>> ts + pd.offsets.BMonthBegin(0)
2655
+ Timestamp('2022-12-01 00:00:00')
2629
2656
"""
2630
2657
_prefix = " BMS"
2631
2658
_day_opt = " business_start"
@@ -3671,7 +3698,9 @@ cdef class Easter(SingleConstructorOffset):
3671
3698
3672
3699
cdef class CustomBusinessDay(BusinessDay):
3673
3700
"""
3674
- DateOffset subclass representing custom business days excluding holidays.
3701
+ DateOffset subclass representing possibly n custom business days.
3702
+
3703
+ In CustomBusinessDay we can use custom weekmask, holidays, and calendar.
3675
3704
3676
3705
Parameters
3677
3706
----------
@@ -3685,13 +3714,50 @@ cdef class CustomBusinessDay(BusinessDay):
3685
3714
List/array of dates to exclude from the set of valid business days,
3686
3715
passed to ``numpy.busdaycalendar``.
3687
3716
calendar : np.busdaycalendar
3717
+ Calendar to integrate.
3688
3718
offset : timedelta, default timedelta(0)
3719
+ Time offset to apply.
3689
3720
3690
3721
Examples
3691
3722
--------
3692
- >>> ts = pd.Timestamp(2022, 8, 5)
3693
- >>> ts + pd.offsets.CustomBusinessDay(1)
3694
- Timestamp('2022-08-08 00:00:00')
3723
+ In the example below the default parameters give the next business day.
3724
+
3725
+ >>> ts = pd.Timestamp(2022, 8, 5, 16)
3726
+ >>> ts + pd.offsets.CustomBusinessDay()
3727
+ Timestamp('2022-08-08 16:00:00')
3728
+
3729
+ Business days can be specified by ``weekmask`` parameter. To convert
3730
+ the returned datetime object to its string representation
3731
+ the function strftime() is used in the next example.
3732
+
3733
+ >>> import datetime as dt
3734
+ >>> freq = pd.offsets.CustomBusinessDay(weekmask="Mon Wed Fri")
3735
+ >>> pd.date_range(dt.datetime(2022, 12, 10), dt.datetime(2022, 12, 21),
3736
+ ... freq=freq).strftime('%a %d %b %Y %H :%M ')
3737
+ Index(['Mon 12 Dec 2022 00:00', 'Wed 14 Dec 2022 00:00',
3738
+ 'Fri 16 Dec 2022 00:00', 'Mon 19 Dec 2022 00:00',
3739
+ 'Wed 21 Dec 2022 00:00'],
3740
+ dtype='object')
3741
+
3742
+ Using NumPy business day calendar you can define custom holidays.
3743
+
3744
+ >>> import datetime as dt
3745
+ >>> bdc = np.busdaycalendar(holidays=['2022-12-12', '2022-12-14'])
3746
+ >>> freq = pd.offsets.CustomBusinessDay(calendar=bdc)
3747
+ >>> pd.date_range(dt.datetime(2022, 12, 10), dt.datetime(2022, 12, 25), freq=freq)
3748
+ DatetimeIndex(['2022-12-13', '2022-12-15', '2022-12-16', '2022-12-19',
3749
+ '2022-12-20', '2022-12-21', '2022-12-22', '2022-12-23'],
3750
+ dtype='datetime64[ns]', freq='C')
3751
+
3752
+ If you want to shift the result on n day you can use the parameter ``offset``.
3753
+
3754
+ >>> pd.Timestamp(2022, 8, 5, 16) + pd.offsets.CustomBusinessDay(1)
3755
+ Timestamp('2022-08-08 16:00:00')
3756
+
3757
+ >>> import datetime as dt
3758
+ >>> ts = pd.Timestamp(2022, 8, 5, 16)
3759
+ >>> ts + pd.offsets.CustomBusinessDay(1, offset=dt.timedelta(days=1))
3760
+ Timestamp('2022-08-09 16:00:00')
3695
3761
"""
3696
3762
3697
3763
_prefix = " C"
0 commit comments