Skip to content

Commit 65d9fe4

Browse files
DOC: GH4607 added clarification to business DateOffset (#34371)
1 parent 75c0e24 commit 65d9fe4

File tree

1 file changed

+96
-9
lines changed

1 file changed

+96
-9
lines changed

pandas/_libs/tslibs/offsets.pyx

+96-9
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,22 @@ cdef class YearOffset(SingleConstructorOffset):
13971397

13981398
cdef class BYearEnd(YearOffset):
13991399
"""
1400-
DateOffset increments between business EOM dates.
1400+
DateOffset increments between the last business day of the year.
1401+
1402+
Examples
1403+
--------
1404+
>>> from pandas.tseries.offset import BYearEnd
1405+
>>> ts = pd.Timestamp('2020-05-24 05:01:15')
1406+
>>> ts - BYearEnd()
1407+
Timestamp('2019-12-31 05:01:15')
1408+
>>> ts + BYearEnd()
1409+
Timestamp('2020-12-31 05:01:15')
1410+
>>> ts + BYearEnd(3)
1411+
Timestamp('2022-12-30 05:01:15')
1412+
>>> ts + BYearEnd(-3)
1413+
Timestamp('2017-12-29 05:01:15')
1414+
>>> ts + BYearEnd(month=11)
1415+
Timestamp('2020-11-30 05:01:15')
14011416
"""
14021417

14031418
_outputName = "BusinessYearEnd"
@@ -1408,7 +1423,20 @@ cdef class BYearEnd(YearOffset):
14081423

14091424
cdef class BYearBegin(YearOffset):
14101425
"""
1411-
DateOffset increments between business year begin dates.
1426+
DateOffset increments between the first business day of the year.
1427+
1428+
Examples
1429+
--------
1430+
>>> from pandas.tseries.offset import BYearBegin
1431+
>>> ts = pd.Timestamp('2020-05-24 05:01:15')
1432+
>>> ts + BYearBegin()
1433+
Timestamp('2021-01-01 05:01:15')
1434+
>>> ts - BYearBegin()
1435+
Timestamp('2020-01-01 05:01:15')
1436+
>>> ts + BYearBegin(-1)
1437+
Timestamp('2020-01-01 05:01:15')
1438+
>>> ts + BYearBegin(2)
1439+
Timestamp('2022-01-03 05:01:15')
14121440
"""
14131441

14141442
_outputName = "BusinessYearBegin"
@@ -1516,11 +1544,24 @@ cdef class QuarterOffset(SingleConstructorOffset):
15161544

15171545
cdef class BQuarterEnd(QuarterOffset):
15181546
"""
1519-
DateOffset increments between business Quarter dates.
1547+
DateOffset increments between the last business day of each Quarter.
15201548
15211549
startingMonth = 1 corresponds to dates like 1/31/2007, 4/30/2007, ...
15221550
startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ...
15231551
startingMonth = 3 corresponds to dates like 3/30/2007, 6/29/2007, ...
1552+
1553+
Examples
1554+
--------
1555+
>>> from pandas.tseries.offset import BQuarterEnd
1556+
>>> ts = pd.Timestamp('2020-05-24 05:01:15')
1557+
>>> ts + BQuarterEnd()
1558+
Timestamp('2020-06-30 05:01:15')
1559+
>>> ts + BQuarterEnd(2)
1560+
Timestamp('2020-09-30 05:01:15')
1561+
>>> ts + BQuarterEnd(1, startingMonth=2)
1562+
Timestamp('2020-05-29 05:01:15')
1563+
>>> ts + BQuarterEnd(startingMonth=2)
1564+
Timestamp('2020-05-29 05:01:15')
15241565
"""
15251566
_outputName = "BusinessQuarterEnd"
15261567
_default_startingMonth = 3
@@ -1529,11 +1570,28 @@ cdef class BQuarterEnd(QuarterOffset):
15291570
_day_opt = "business_end"
15301571

15311572

1532-
# TODO: This is basically the same as BQuarterEnd
15331573
cdef class BQuarterBegin(QuarterOffset):
1574+
"""
1575+
DateOffset increments between the first business day of each Quarter.
1576+
1577+
startingMonth = 1 corresponds to dates like 1/01/2007, 4/01/2007, ...
1578+
startingMonth = 2 corresponds to dates like 2/01/2007, 5/01/2007, ...
1579+
startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007, ...
1580+
1581+
Examples
1582+
--------
1583+
>>> from pandas.tseries.offset import BQuarterBegin
1584+
>>> ts = pd.Timestamp('2020-05-24 05:01:15')
1585+
>>> ts + BQuarterBegin()
1586+
Timestamp('2020-06-01 05:01:15')
1587+
>>> ts + BQuarterBegin(2)
1588+
Timestamp('2020-09-01 05:01:15')
1589+
>>> ts + BQuarterBegin(startingMonth=2)
1590+
Timestamp('2020-08-03 05:01:15')
1591+
>>> ts + BQuarterBegin(-1)
1592+
Timestamp('2020-03-02 05:01:15')
1593+
"""
15341594
_outputName = "BusinessQuarterBegin"
1535-
# I suspect this is wrong for *all* of them.
1536-
# TODO: What does the above comment refer to?
15371595
_default_startingMonth = 3
15381596
_from_name_startingMonth = 1
15391597
_prefix = "BQS"
@@ -1542,7 +1600,7 @@ cdef class BQuarterBegin(QuarterOffset):
15421600

15431601
cdef class QuarterEnd(QuarterOffset):
15441602
"""
1545-
DateOffset increments between business Quarter dates.
1603+
DateOffset increments between Quarter end dates.
15461604
15471605
startingMonth = 1 corresponds to dates like 1/31/2007, 4/30/2007, ...
15481606
startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ...
@@ -1555,6 +1613,13 @@ cdef class QuarterEnd(QuarterOffset):
15551613

15561614

15571615
cdef class QuarterBegin(QuarterOffset):
1616+
"""
1617+
DateOffset increments between Quarter start dates.
1618+
1619+
startingMonth = 1 corresponds to dates like 1/01/2007, 4/01/2007, ...
1620+
startingMonth = 2 corresponds to dates like 2/01/2007, 5/01/2007, ...
1621+
startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007, ...
1622+
"""
15581623
_outputName = "QuarterBegin"
15591624
_default_startingMonth = 3
15601625
_from_name_startingMonth = 1
@@ -1601,15 +1666,37 @@ cdef class MonthBegin(MonthOffset):
16011666

16021667
cdef class BusinessMonthEnd(MonthOffset):
16031668
"""
1604-
DateOffset increments between business EOM dates.
1669+
DateOffset increments between the last business day of the month
1670+
1671+
Examples
1672+
--------
1673+
>>> from pandas.tseries.offset import BMonthEnd
1674+
>>> ts = pd.Timestamp('2020-05-24 05:01:15')
1675+
>>> ts + BMonthEnd()
1676+
Timestamp('2020-05-29 05:01:15')
1677+
>>> ts + BMonthEnd(2)
1678+
Timestamp('2020-06-30 05:01:15')
1679+
>>> ts + BMonthEnd(-2)
1680+
Timestamp('2020-03-31 05:01:15')
16051681
"""
16061682
_prefix = "BM"
16071683
_day_opt = "business_end"
16081684

16091685

16101686
cdef class BusinessMonthBegin(MonthOffset):
16111687
"""
1612-
DateOffset of one business month at beginning.
1688+
DateOffset of one month at the first business day.
1689+
1690+
Examples
1691+
--------
1692+
>>> from pandas.tseries.offset import BMonthBegin
1693+
>>> ts=pd.Timestamp('2020-05-24 05:01:15')
1694+
>>> ts + BMonthBegin()
1695+
Timestamp('2020-06-01 05:01:15')
1696+
>>> ts + BMonthBegin(2)
1697+
Timestamp('2020-07-01 05:01:15')
1698+
>>> ts + BMonthBegin(-3)
1699+
Timestamp('2020-03-02 05:01:15')
16131700
"""
16141701
_prefix = "BMS"
16151702
_day_opt = "business_start"

0 commit comments

Comments
 (0)