Skip to content

Commit 1fa2453

Browse files
Add tabular string of offset aliases for docstring appending
Table is derived from first lines of docstrings; all classes in `_all__` had docstrings revised.
1 parent d0342aa commit 1fa2453

File tree

1 file changed

+56
-28
lines changed

1 file changed

+56
-28
lines changed

pandas/tseries/offsets.py

+56-28
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ def _from_name(cls, suffix=None):
292292

293293

294294
class BusinessDay(CacheableOffset, SingleConstructorOffset):
295-
"""
296-
DateOffset subclass representing possibly n business days
297-
"""
295+
"""Business day (weekday)"""
298296
_prefix = 'B'
299297

300298
def __init__(self, n=1, **kwds):
@@ -425,7 +423,8 @@ def onOffset(cls, dt):
425423

426424

427425
class CustomBusinessDay(BusinessDay):
428-
"""
426+
"""Custom representation **EXPERIMENTAL**
427+
429428
**EXPERIMENTAL** DateOffset subclass representing possibly n business days
430429
excluding holidays
431430
@@ -445,6 +444,7 @@ class CustomBusinessDay(BusinessDay):
445444
holidays : list
446445
list/array of dates to exclude from the set of valid business days,
447446
passed to ``numpy.busdaycalendar``
447+
448448
"""
449449

450450
_cacheable = False
@@ -547,7 +547,7 @@ def name(self):
547547

548548

549549
class MonthEnd(CacheableOffset, MonthOffset):
550-
"""DateOffset of one month end"""
550+
"""Calendar month end date"""
551551

552552
def apply(self, other):
553553
other = datetime(other.year, other.month, other.day,
@@ -571,7 +571,7 @@ def onOffset(cls, dt):
571571

572572

573573
class MonthBegin(CacheableOffset, MonthOffset):
574-
"""DateOffset of one month at beginning"""
574+
"""Calendar month begin date"""
575575

576576
def apply(self, other):
577577
n = self.n
@@ -590,7 +590,7 @@ def onOffset(cls, dt):
590590

591591

592592
class BusinessMonthEnd(CacheableOffset, MonthOffset):
593-
"""DateOffset increments between business EOM dates"""
593+
"""Business month end dates"""
594594

595595
def isAnchored(self):
596596
return (self.n == 1)
@@ -618,7 +618,7 @@ def apply(self, other):
618618

619619

620620
class BusinessMonthBegin(CacheableOffset, MonthOffset):
621-
"""DateOffset of one business month at beginning"""
621+
"""Business month begin date"""
622622

623623
def apply(self, other):
624624
n = self.n
@@ -653,13 +653,13 @@ def onOffset(cls, dt):
653653

654654

655655
class Week(CacheableOffset, DateOffset):
656-
"""
657-
Weekly offset
656+
"""Week, optionally anchored on day of the week
658657
659658
Parameters
660659
----------
661660
weekday : int, default None
662661
Always generate specific day of week. 0 for Monday
662+
663663
"""
664664

665665
def __init__(self, n=1, **kwds):
@@ -720,6 +720,7 @@ def _from_name(cls, suffix=None):
720720
weekday = _weekday_to_int[suffix]
721721
return cls(weekday=weekday)
722722

723+
723724
class WeekDay(object):
724725
MON = 0
725726
TUE = 1
@@ -743,8 +744,7 @@ class WeekDay(object):
743744

744745

745746
class WeekOfMonth(CacheableOffset, DateOffset):
746-
"""
747-
Describes monthly dates like "the Tuesday of the 2nd week of each month"
747+
"""Dates like "Tuesday of the 2nd week each month"
748748
749749
Parameters
750750
----------
@@ -759,6 +759,7 @@ class WeekOfMonth(CacheableOffset, DateOffset):
759759
4: Fridays
760760
5: Saturdays
761761
6: Sundays
762+
762763
"""
763764

764765
def __init__(self, n=1, **kwds):
@@ -828,9 +829,9 @@ def _from_name(cls, suffix=None):
828829
weekday = _weekday_to_int[suffix[1:]]
829830
return cls(week=week, weekday=weekday)
830831

832+
831833
class LastWeekOfMonth(CacheableOffset, DateOffset):
832-
"""
833-
Describes monthly dates in last week of month like "the last Tuesday of each month"
834+
"""Dates like "last Tuesday of the month"
834835
835836
Parameters
836837
----------
@@ -843,7 +844,9 @@ class LastWeekOfMonth(CacheableOffset, DateOffset):
843844
4: Fridays
844845
5: Saturdays
845846
6: Sundays
847+
846848
"""
849+
847850
def __init__(self, n=1, **kwds):
848851
self.n = n
849852
self.weekday = kwds['weekday']
@@ -939,10 +942,12 @@ def rule_code(self):
939942

940943

941944
class BQuarterEnd(CacheableOffset, QuarterOffset):
942-
"""DateOffset increments between business Quarter dates
945+
"""Business quarter end date
946+
943947
startingMonth = 1 corresponds to dates like 1/31/2007, 4/30/2007, ...
944948
startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ...
945949
startingMonth = 3 corresponds to dates like 3/30/2007, 6/29/2007, ...
950+
946951
"""
947952
_outputName = 'BusinessQuarterEnd'
948953
_default_startingMonth = 3
@@ -977,9 +982,9 @@ def onOffset(self, dt):
977982
modMonth = (dt.month - self.startingMonth) % 3
978983
return BMonthEnd().onOffset(dt) and modMonth == 0
979984

985+
980986
class FY5253(CacheableOffset, DateOffset):
981-
"""
982-
Describes 52-53 week fiscal year. This is also known as a 4-4-5 calendar.
987+
"""End date, 52-53 week fiscal year (4-4-5 calendar)
983988
984989
It is used by companies that desire that their
985990
fiscal year always end on the same day of the week.
@@ -1013,6 +1018,7 @@ class FY5253(CacheableOffset, DateOffset):
10131018
startingMonth : The month in which fiscal years end. {1, 2, ... 12}
10141019
variation : str
10151020
{"nearest", "last"} for "LastOfMonth" or "NearestEndMonth"
1021+
10161022
"""
10171023

10181024
_prefix = 'RE'
@@ -1142,13 +1148,12 @@ def _parse_suffix(cls, varion_code, startingMonth_code, weekday_code):
11421148
def _from_name(cls, *args):
11431149
return cls(**cls._parse_suffix(*args))
11441150

1151+
11451152
class FY5253Quarter(CacheableOffset, DateOffset):
1146-
"""
1147-
DateOffset increments between business quarter dates
1148-
for 52-53 week fiscal year (also known as a 4-4-5 calendar).
1153+
"""Quarter end, 52-53 week fiscal year (4-4-5 calendar)
11491154
1150-
It is used by companies that desire that their
1151-
fiscal year always end on the same day of the week.
1155+
The 4-4-5 calendar is used by companies that desire that
1156+
their fiscal year always end on the same day of the week.
11521157
11531158
It is a method of managing accounting periods.
11541159
It is a common calendar structure for some industries,
@@ -1184,6 +1189,7 @@ class FY5253Quarter(CacheableOffset, DateOffset):
11841189
or 14 week when needed. {1,2,3,4}
11851190
variation : str
11861191
{"nearest", "last"} for "LastOfMonth" or "NearestEndMonth"
1192+
11871193
"""
11881194

11891195
_prefix = 'REQ'
@@ -1311,6 +1317,8 @@ def _from_name(cls, *args):
13111317

13121318
# TODO: This is basically the same as BQuarterEnd
13131319
class BQuarterBegin(CacheableOffset, QuarterOffset):
1320+
"""Business quarter begin date"""
1321+
13141322
_outputName = "BusinessQuarterBegin"
13151323
# I suspect this is wrong for *all* of them.
13161324
_default_startingMonth = 3
@@ -1348,7 +1356,8 @@ def apply(self, other):
13481356

13491357

13501358
class QuarterEnd(CacheableOffset, QuarterOffset):
1351-
"""DateOffset increments between business Quarter dates
1359+
"""Calendar quarter end date
1360+
13521361
startingMonth = 1 corresponds to dates like 1/31/2007, 4/30/2007, ...
13531362
startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ...
13541363
startingMonth = 3 corresponds to dates like 3/31/2007, 6/30/2007, ...
@@ -1389,6 +1398,8 @@ def onOffset(self, dt):
13891398

13901399

13911400
class QuarterBegin(CacheableOffset, QuarterOffset):
1401+
"""Calendar quarter begin date"""
1402+
13921403
_outputName = 'QuarterBegin'
13931404
_default_startingMonth = 3
13941405
_from_name_startingMonth = 1
@@ -1441,7 +1452,8 @@ def rule_code(self):
14411452

14421453

14431454
class BYearEnd(CacheableOffset, YearOffset):
1444-
"""DateOffset increments between business EOM dates"""
1455+
"""Business year end date"""
1456+
14451457
_outputName = 'BusinessYearEnd'
14461458
_default_month = 12
14471459
_prefix = 'BA'
@@ -1478,7 +1490,8 @@ def apply(self, other):
14781490

14791491

14801492
class BYearBegin(CacheableOffset, YearOffset):
1481-
"""DateOffset increments between business year begin dates"""
1493+
"""Business year begin date"""
1494+
14821495
_outputName = 'BusinessYearBegin'
14831496
_default_month = 1
14841497
_prefix = 'BAS'
@@ -1510,7 +1523,8 @@ def apply(self, other):
15101523

15111524

15121525
class YearEnd(CacheableOffset, YearOffset):
1513-
"""DateOffset increments between calendar year ends"""
1526+
"""Calendar year end date"""
1527+
15141528
_default_month = 12
15151529
_prefix = 'A'
15161530

@@ -1566,7 +1580,8 @@ def onOffset(self, dt):
15661580

15671581

15681582
class YearBegin(CacheableOffset, YearOffset):
1569-
"""DateOffset increments between calendar year begin dates"""
1583+
"""Calendar year begin date"""
1584+
15701585
_default_month = 1
15711586
_prefix = 'AS'
15721587

@@ -1731,35 +1746,42 @@ def _delta_to_nanoseconds(delta):
17311746

17321747

17331748
class Day(CacheableOffset, Tick):
1749+
"""One calendar day"""
17341750
_inc = timedelta(1)
17351751
_prefix = 'D'
17361752

17371753

17381754
class Hour(Tick):
1755+
"""One hour"""
17391756
_inc = timedelta(0, 3600)
17401757
_prefix = 'H'
17411758

17421759

17431760
class Minute(Tick):
1761+
"""One minute"""
17441762
_inc = timedelta(0, 60)
17451763
_prefix = 'T'
1746-
1764+
17471765

17481766
class Second(Tick):
1767+
"""One second"""
17491768
_inc = timedelta(0, 1)
17501769
_prefix = 'S'
17511770

17521771

17531772
class Milli(Tick):
1773+
"""One millisecond"""
17541774
_prefix = 'L'
17551775

17561776

17571777
class Micro(Tick):
1778+
"""One microsecond"""
17581779
_inc = timedelta(microseconds=1)
17591780
_prefix = 'U'
17601781

17611782

17621783
class Nano(Tick):
1784+
"""One nanosecond"""
17631785
_inc = np.timedelta64(1, 'ns') if not _np_version_under1p7 else 1
17641786
_prefix = 'N'
17651787

@@ -1796,6 +1818,7 @@ def generate_range(start=None, end=None, periods=None,
17961818
start : datetime (default None)
17971819
end : datetime (default None)
17981820
periods : int, optional
1821+
offset : DateOffset, default BusinessDay
17991822
time_rule : (legacy) name of DateOffset object to be used, optional
18001823
Corresponds with names expected by tseries.frequencies.get_offset
18011824
@@ -1875,6 +1898,11 @@ def generate_range(start=None, end=None, periods=None,
18751898
FY5253Quarter,
18761899
])
18771900

1901+
_alias_doc = 'Offset Aliases\n--------------\n' + \
1902+
'\n'.join(sorted([item.ljust(max([len(s) for s in __all__])+2) + \
1903+
(locals()[item].__doc__.split('\n')[0].strip() or '<no docstring found>') \
1904+
for item in __all__]))
1905+
18781906
if not _np_version_under1p7:
18791907
# Only 1.7+ supports nanosecond resolution
18801908
prefix_mapping['N'] = Nano

0 commit comments

Comments
 (0)