Skip to content

Commit 0db27c0

Browse files
authored
DOC: add parameters and examples to CustomBusinessMonthBegin/End (#55328)
* add parameters and examples to CustomBusinessMonthBegin/End * move _attributes to _CustomBusinessMonth
1 parent 6f0cd8d commit 0db27c0

File tree

1 file changed

+114
-22
lines changed

1 file changed

+114
-22
lines changed

pandas/_libs/tslibs/offsets.pyx

+114-22
Original file line numberDiff line numberDiff line change
@@ -4329,28 +4329,6 @@ cdef class CustomBusinessHour(BusinessHour):
43294329

43304330

43314331
cdef class _CustomBusinessMonth(BusinessMixin):
4332-
"""
4333-
DateOffset subclass representing custom business month(s).
4334-
4335-
Increments between beginning/end of month dates.
4336-
4337-
Parameters
4338-
----------
4339-
n : int, default 1
4340-
The number of months represented.
4341-
normalize : bool, default False
4342-
Normalize start/end dates to midnight before generating date range.
4343-
weekmask : str, Default 'Mon Tue Wed Thu Fri'
4344-
Weekmask of valid business days, passed to ``numpy.busdaycalendar``.
4345-
holidays : list
4346-
List/array of dates to exclude from the set of valid business days,
4347-
passed to ``numpy.busdaycalendar``.
4348-
calendar : np.busdaycalendar
4349-
Calendar to integrate.
4350-
offset : timedelta, default timedelta(0)
4351-
Time offset to apply.
4352-
"""
4353-
43544332
_attributes = tuple(
43554333
["n", "normalize", "weekmask", "holidays", "calendar", "offset"]
43564334
)
@@ -4426,10 +4404,124 @@ cdef class _CustomBusinessMonth(BusinessMixin):
44264404

44274405

44284406
cdef class CustomBusinessMonthEnd(_CustomBusinessMonth):
4407+
"""
4408+
DateOffset subclass representing custom business month(s).
4409+
4410+
Increments between end of month dates.
4411+
4412+
Parameters
4413+
----------
4414+
n : int, default 1
4415+
The number of months represented.
4416+
normalize : bool, default False
4417+
Normalize end dates to midnight before generating date range.
4418+
weekmask : str, Default 'Mon Tue Wed Thu Fri'
4419+
Weekmask of valid business days, passed to ``numpy.busdaycalendar``.
4420+
holidays : list
4421+
List/array of dates to exclude from the set of valid business days,
4422+
passed to ``numpy.busdaycalendar``.
4423+
calendar : np.busdaycalendar
4424+
Calendar to integrate.
4425+
offset : timedelta, default timedelta(0)
4426+
Time offset to apply.
4427+
4428+
See Also
4429+
--------
4430+
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
4431+
4432+
Examples
4433+
--------
4434+
In the example below we use the default parameters.
4435+
4436+
>>> ts = pd.Timestamp(2022, 8, 5)
4437+
>>> ts + pd.offsets.CustomBusinessMonthEnd()
4438+
Timestamp('2022-08-31 00:00:00')
4439+
4440+
Custom business month end can be specified by ``weekmask`` parameter.
4441+
To convert the returned datetime object to its string representation
4442+
the function strftime() is used in the next example.
4443+
4444+
>>> import datetime as dt
4445+
>>> freq = pd.offsets.CustomBusinessMonthEnd(weekmask="Wed Thu")
4446+
>>> pd.date_range(dt.datetime(2022, 7, 10), dt.datetime(2022, 12, 18),
4447+
... freq=freq).strftime('%a %d %b %Y %H:%M')
4448+
Index(['Thu 28 Jul 2022 00:00', 'Wed 31 Aug 2022 00:00',
4449+
'Thu 29 Sep 2022 00:00', 'Thu 27 Oct 2022 00:00',
4450+
'Wed 30 Nov 2022 00:00'],
4451+
dtype='object')
4452+
4453+
Using NumPy business day calendar you can define custom holidays.
4454+
4455+
>>> import datetime as dt
4456+
>>> bdc = np.busdaycalendar(holidays=['2022-08-01', '2022-09-30',
4457+
... '2022-10-31', '2022-11-01'])
4458+
>>> freq = pd.offsets.CustomBusinessMonthEnd(calendar=bdc)
4459+
>>> pd.date_range(dt.datetime(2022, 7, 10), dt.datetime(2022, 11, 10), freq=freq)
4460+
DatetimeIndex(['2022-07-29', '2022-08-31', '2022-09-29', '2022-10-28'],
4461+
dtype='datetime64[ns]', freq='CBM')
4462+
"""
4463+
44294464
_prefix = "CBM"
44304465

44314466

44324467
cdef class CustomBusinessMonthBegin(_CustomBusinessMonth):
4468+
"""
4469+
DateOffset subclass representing custom business month(s).
4470+
4471+
Increments between beginning of month dates.
4472+
4473+
Parameters
4474+
----------
4475+
n : int, default 1
4476+
The number of months represented.
4477+
normalize : bool, default False
4478+
Normalize start dates to midnight before generating date range.
4479+
weekmask : str, Default 'Mon Tue Wed Thu Fri'
4480+
Weekmask of valid business days, passed to ``numpy.busdaycalendar``.
4481+
holidays : list
4482+
List/array of dates to exclude from the set of valid business days,
4483+
passed to ``numpy.busdaycalendar``.
4484+
calendar : np.busdaycalendar
4485+
Calendar to integrate.
4486+
offset : timedelta, default timedelta(0)
4487+
Time offset to apply.
4488+
4489+
See Also
4490+
--------
4491+
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
4492+
4493+
Examples
4494+
--------
4495+
In the example below we use the default parameters.
4496+
4497+
>>> ts = pd.Timestamp(2022, 8, 5)
4498+
>>> ts + pd.offsets.CustomBusinessMonthBegin()
4499+
Timestamp('2022-09-01 00:00:00')
4500+
4501+
Custom business month start can be specified by ``weekmask`` parameter.
4502+
To convert the returned datetime object to its string representation
4503+
the function strftime() is used in the next example.
4504+
4505+
>>> import datetime as dt
4506+
>>> freq = pd.offsets.CustomBusinessMonthBegin(weekmask="Wed Thu")
4507+
>>> pd.date_range(dt.datetime(2022, 7, 10), dt.datetime(2022, 12, 18),
4508+
... freq=freq).strftime('%a %d %b %Y %H:%M')
4509+
Index(['Wed 03 Aug 2022 00:00', 'Thu 01 Sep 2022 00:00',
4510+
'Wed 05 Oct 2022 00:00', 'Wed 02 Nov 2022 00:00',
4511+
'Thu 01 Dec 2022 00:00'],
4512+
dtype='object')
4513+
4514+
Using NumPy business day calendar you can define custom holidays.
4515+
4516+
>>> import datetime as dt
4517+
>>> bdc = np.busdaycalendar(holidays=['2022-08-01', '2022-09-30',
4518+
... '2022-10-31', '2022-11-01'])
4519+
>>> freq = pd.offsets.CustomBusinessMonthBegin(calendar=bdc)
4520+
>>> pd.date_range(dt.datetime(2022, 7, 10), dt.datetime(2022, 11, 10), freq=freq)
4521+
DatetimeIndex(['2022-08-02', '2022-09-01', '2022-10-03', '2022-11-02'],
4522+
dtype='datetime64[ns]', freq='CBMS')
4523+
"""
4524+
44334525
_prefix = "CBMS"
44344526

44354527

0 commit comments

Comments
 (0)