@@ -929,8 +929,9 @@ def name(self):
929929 if self .isAnchored :
930930 return self .rule_code
931931 else :
932+ month = liboffsets ._int_to_month [self .n ]
932933 return "{code}-{month}" .format (code = self .rule_code ,
933- month = _int_to_month [ self . n ] )
934+ month = month )
934935
935936 def onOffset (self , dt ):
936937 if self .normalize and not _is_normalized (dt ):
@@ -950,28 +951,23 @@ def apply(self, other):
950951
951952 return shift_month (other , n , self ._day_opt )
952953
954+ @apply_index_wraps
955+ def apply_index (self , i ):
956+ shifted = liboffsets .shift_months (i .asi8 , self .n , self ._day_opt )
957+ return i ._shallow_copy (shifted )
958+
953959
954960class MonthEnd (MonthOffset ):
955961 """DateOffset of one month end"""
956962 _prefix = 'M'
957963 _day_opt = 'end'
958964
959- @apply_index_wraps
960- def apply_index (self , i ):
961- shifted = liboffsets .shift_months (i .asi8 , self .n , self ._day_opt )
962- return i ._shallow_copy (shifted )
963-
964965
965966class MonthBegin (MonthOffset ):
966967 """DateOffset of one month at beginning"""
967968 _prefix = 'MS'
968969 _day_opt = 'start'
969970
970- @apply_index_wraps
971- def apply_index (self , i ):
972- shifted = liboffsets .shift_months (i .asi8 , self .n , self ._day_opt )
973- return i ._shallow_copy (shifted )
974-
975971
976972class BusinessMonthEnd (MonthOffset ):
977973 """DateOffset increments between business EOM dates"""
@@ -1008,6 +1004,7 @@ class CustomBusinessMonthEnd(BusinessMixin, MonthOffset):
10081004 _prefix = 'CBM'
10091005
10101006 onOffset = DateOffset .onOffset # override MonthOffset method
1007+ apply_index = DateOffset .apply_index # override MonthOffset method
10111008
10121009 def __init__ (self , n = 1 , normalize = False , weekmask = 'Mon Tue Wed Thu Fri' ,
10131010 holidays = None , calendar = None , offset = timedelta (0 )):
@@ -1083,6 +1080,7 @@ class CustomBusinessMonthBegin(BusinessMixin, MonthOffset):
10831080 _prefix = 'CBMS'
10841081
10851082 onOffset = DateOffset .onOffset # override MonthOffset method
1083+ apply_index = DateOffset .apply_index # override MonthOffset method
10861084
10871085 def __init__ (self , n = 1 , normalize = False , weekmask = 'Mon Tue Wed Thu Fri' ,
10881086 holidays = None , calendar = None , offset = timedelta (0 )):
@@ -1603,15 +1601,15 @@ def isAnchored(self):
16031601 def _from_name (cls , suffix = None ):
16041602 kwargs = {}
16051603 if suffix :
1606- kwargs ['startingMonth' ] = _month_to_int [suffix ]
1604+ kwargs ['startingMonth' ] = liboffsets . _month_to_int [suffix ]
16071605 else :
16081606 if cls ._from_name_startingMonth is not None :
16091607 kwargs ['startingMonth' ] = cls ._from_name_startingMonth
16101608 return cls (** kwargs )
16111609
16121610 @property
16131611 def rule_code (self ):
1614- month = _int_to_month [self .startingMonth ]
1612+ month = liboffsets . _int_to_month [self .startingMonth ]
16151613 return '{prefix}-{month}' .format (prefix = self ._prefix , month = month )
16161614
16171615 @apply_wraps
@@ -1631,6 +1629,12 @@ def apply(self, other):
16311629
16321630 return shift_month (other , 3 * n - months_since , self ._day_opt )
16331631
1632+ def onOffset (self , dt ):
1633+ if self .normalize and not _is_normalized (dt ):
1634+ return False
1635+ modMonth = (dt .month - self .startingMonth ) % 3
1636+ return modMonth == 0 and dt .day == self ._get_offset_day (dt )
1637+
16341638
16351639class BQuarterEnd (QuarterOffset ):
16361640 """DateOffset increments between business Quarter dates
@@ -1644,16 +1648,6 @@ class BQuarterEnd(QuarterOffset):
16441648 _prefix = 'BQ'
16451649 _day_opt = 'business_end'
16461650
1647- def onOffset (self , dt ):
1648- if self .normalize and not _is_normalized (dt ):
1649- return False
1650- modMonth = (dt .month - self .startingMonth ) % 3
1651- return modMonth == 0 and dt .day == self ._get_offset_day (dt )
1652-
1653-
1654- _int_to_month = tslib ._MONTH_ALIASES
1655- _month_to_int = {v : k for k , v in _int_to_month .items ()}
1656-
16571651
16581652# TODO: This is basically the same as BQuarterEnd
16591653class BQuarterBegin (QuarterOffset ):
@@ -1680,12 +1674,6 @@ class QuarterEnd(EndMixin, QuarterOffset):
16801674 def apply_index (self , i ):
16811675 return self ._end_apply_index (i , self .freqstr )
16821676
1683- def onOffset (self , dt ):
1684- if self .normalize and not _is_normalized (dt ):
1685- return False
1686- modMonth = (dt .month - self .startingMonth ) % 3
1687- return modMonth == 0 and dt .day == self ._get_offset_day (dt )
1688-
16891677
16901678class QuarterBegin (BeginMixin , QuarterOffset ):
16911679 _outputName = 'QuarterBegin'
@@ -1697,7 +1685,8 @@ class QuarterBegin(BeginMixin, QuarterOffset):
16971685 @apply_index_wraps
16981686 def apply_index (self , i ):
16991687 freq_month = 12 if self .startingMonth == 1 else self .startingMonth - 1
1700- freqstr = 'Q-{month}' .format (month = _int_to_month [freq_month ])
1688+ month = liboffsets ._int_to_month [freq_month ]
1689+ freqstr = 'Q-{month}' .format (month = month )
17011690 return self ._beg_apply_index (i , freqstr )
17021691
17031692
@@ -1738,12 +1727,12 @@ def __init__(self, n=1, normalize=False, month=None):
17381727 def _from_name (cls , suffix = None ):
17391728 kwargs = {}
17401729 if suffix :
1741- kwargs ['month' ] = _month_to_int [suffix ]
1730+ kwargs ['month' ] = liboffsets . _month_to_int [suffix ]
17421731 return cls (** kwargs )
17431732
17441733 @property
17451734 def rule_code (self ):
1746- month = _int_to_month [self .month ]
1735+ month = liboffsets . _int_to_month [self .month ]
17471736 return '{prefix}-{month}' .format (prefix = self ._prefix , month = month )
17481737
17491738
@@ -1784,7 +1773,8 @@ class YearBegin(BeginMixin, YearOffset):
17841773 @apply_index_wraps
17851774 def apply_index (self , i ):
17861775 freq_month = 12 if self .month == 1 else self .month - 1
1787- freqstr = 'A-{month}' .format (month = _int_to_month [freq_month ])
1776+ month = liboffsets ._int_to_month [freq_month ]
1777+ freqstr = 'A-{month}' .format (month = month )
17881778 return self ._beg_apply_index (i , freqstr )
17891779
17901780
@@ -1969,7 +1959,7 @@ def _get_suffix_prefix(self):
19691959
19701960 def get_rule_code_suffix (self ):
19711961 prefix = self ._get_suffix_prefix ()
1972- month = _int_to_month [self .startingMonth ]
1962+ month = liboffsets . _int_to_month [self .startingMonth ]
19731963 weekday = _int_to_weekday [self .weekday ]
19741964 return '{prefix}-{month}-{weekday}' .format (prefix = prefix , month = month ,
19751965 weekday = weekday )
@@ -1984,7 +1974,7 @@ def _parse_suffix(cls, varion_code, startingMonth_code, weekday_code):
19841974 raise ValueError ("Unable to parse varion_code: "
19851975 "{code}" .format (code = varion_code ))
19861976
1987- startingMonth = _month_to_int [startingMonth_code ]
1977+ startingMonth = liboffsets . _month_to_int [startingMonth_code ]
19881978 weekday = _weekday_to_int [weekday_code ]
19891979
19901980 return {"weekday" : weekday ,
0 commit comments