@@ -924,8 +924,9 @@ def name(self):
924
924
if self .isAnchored :
925
925
return self .rule_code
926
926
else :
927
+ month = liboffsets ._int_to_month [self .n ]
927
928
return "{code}-{month}" .format (code = self .rule_code ,
928
- month = _int_to_month [ self . n ] )
929
+ month = month )
929
930
930
931
def onOffset (self , dt ):
931
932
if self .normalize and not _is_normalized (dt ):
@@ -945,28 +946,23 @@ def apply(self, other):
945
946
946
947
return shift_month (other , n , self ._day_opt )
947
948
949
+ @apply_index_wraps
950
+ def apply_index (self , i ):
951
+ shifted = liboffsets .shift_months (i .asi8 , self .n , self ._day_opt )
952
+ return i ._shallow_copy (shifted )
953
+
948
954
949
955
class MonthEnd (MonthOffset ):
950
956
"""DateOffset of one month end"""
951
957
_prefix = 'M'
952
958
_day_opt = 'end'
953
959
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
-
959
960
960
961
class MonthBegin (MonthOffset ):
961
962
"""DateOffset of one month at beginning"""
962
963
_prefix = 'MS'
963
964
_day_opt = 'start'
964
965
965
- @apply_index_wraps
966
- def apply_index (self , i ):
967
- shifted = liboffsets .shift_months (i .asi8 , self .n , self ._day_opt )
968
- return i ._shallow_copy (shifted )
969
-
970
966
971
967
class BusinessMonthEnd (MonthOffset ):
972
968
"""DateOffset increments between business EOM dates"""
@@ -1202,6 +1198,7 @@ class CustomBusinessMonthEnd(BusinessMixin, MonthOffset):
1202
1198
_prefix = 'CBM'
1203
1199
1204
1200
onOffset = DateOffset .onOffset # override MonthOffset method
1201
+ apply_index = DateOffset .apply_index # override MonthOffset method
1205
1202
1206
1203
def __init__ (self , n = 1 , normalize = False , weekmask = 'Mon Tue Wed Thu Fri' ,
1207
1204
holidays = None , calendar = None , offset = timedelta (0 )):
@@ -1275,6 +1272,7 @@ class CustomBusinessMonthBegin(BusinessMixin, MonthOffset):
1275
1272
_prefix = 'CBMS'
1276
1273
1277
1274
onOffset = DateOffset .onOffset # override MonthOffset method
1275
+ apply_index = DateOffset .apply_index # override MonthOffset method
1278
1276
1279
1277
def __init__ (self , n = 1 , normalize = False , weekmask = 'Mon Tue Wed Thu Fri' ,
1280
1278
holidays = None , calendar = None , offset = timedelta (0 )):
@@ -1590,15 +1588,15 @@ def isAnchored(self):
1590
1588
def _from_name (cls , suffix = None ):
1591
1589
kwargs = {}
1592
1590
if suffix :
1593
- kwargs ['startingMonth' ] = _month_to_int [suffix ]
1591
+ kwargs ['startingMonth' ] = liboffsets . _month_to_int [suffix ]
1594
1592
else :
1595
1593
if cls ._from_name_startingMonth is not None :
1596
1594
kwargs ['startingMonth' ] = cls ._from_name_startingMonth
1597
1595
return cls (** kwargs )
1598
1596
1599
1597
@property
1600
1598
def rule_code (self ):
1601
- month = _int_to_month [self .startingMonth ]
1599
+ month = liboffsets . _int_to_month [self .startingMonth ]
1602
1600
return '{prefix}-{month}' .format (prefix = self ._prefix , month = month )
1603
1601
1604
1602
@apply_wraps
@@ -1618,6 +1616,12 @@ def apply(self, other):
1618
1616
1619
1617
return shift_month (other , 3 * n - months_since , self ._day_opt )
1620
1618
1619
+ def onOffset (self , dt ):
1620
+ if self .normalize and not _is_normalized (dt ):
1621
+ return False
1622
+ modMonth = (dt .month - self .startingMonth ) % 3
1623
+ return modMonth == 0 and dt .day == self ._get_offset_day (dt )
1624
+
1621
1625
1622
1626
class BQuarterEnd (QuarterOffset ):
1623
1627
"""DateOffset increments between business Quarter dates
@@ -1631,16 +1635,6 @@ class BQuarterEnd(QuarterOffset):
1631
1635
_prefix = 'BQ'
1632
1636
_day_opt = 'business_end'
1633
1637
1634
- def onOffset (self , dt ):
1635
- if self .normalize and not _is_normalized (dt ):
1636
- return False
1637
- modMonth = (dt .month - self .startingMonth ) % 3
1638
- return modMonth == 0 and dt .day == self ._get_offset_day (dt )
1639
-
1640
-
1641
- _int_to_month = tslib ._MONTH_ALIASES
1642
- _month_to_int = {v : k for k , v in _int_to_month .items ()}
1643
-
1644
1638
1645
1639
# TODO: This is basically the same as BQuarterEnd
1646
1640
class BQuarterBegin (QuarterOffset ):
@@ -1667,12 +1661,6 @@ class QuarterEnd(EndMixin, QuarterOffset):
1667
1661
def apply_index (self , i ):
1668
1662
return self ._end_apply_index (i , self .freqstr )
1669
1663
1670
- def onOffset (self , dt ):
1671
- if self .normalize and not _is_normalized (dt ):
1672
- return False
1673
- modMonth = (dt .month - self .startingMonth ) % 3
1674
- return modMonth == 0 and dt .day == self ._get_offset_day (dt )
1675
-
1676
1664
1677
1665
class QuarterBegin (BeginMixin , QuarterOffset ):
1678
1666
_outputName = 'QuarterBegin'
@@ -1684,7 +1672,8 @@ class QuarterBegin(BeginMixin, QuarterOffset):
1684
1672
@apply_index_wraps
1685
1673
def apply_index (self , i ):
1686
1674
freq_month = 12 if self .startingMonth == 1 else self .startingMonth - 1
1687
- freqstr = 'Q-{month}' .format (month = _int_to_month [freq_month ])
1675
+ month = liboffsets ._int_to_month [freq_month ]
1676
+ freqstr = 'Q-{month}' .format (month = month )
1688
1677
return self ._beg_apply_index (i , freqstr )
1689
1678
1690
1679
@@ -1725,12 +1714,12 @@ def __init__(self, n=1, normalize=False, month=None):
1725
1714
def _from_name (cls , suffix = None ):
1726
1715
kwargs = {}
1727
1716
if suffix :
1728
- kwargs ['month' ] = _month_to_int [suffix ]
1717
+ kwargs ['month' ] = liboffsets . _month_to_int [suffix ]
1729
1718
return cls (** kwargs )
1730
1719
1731
1720
@property
1732
1721
def rule_code (self ):
1733
- month = _int_to_month [self .month ]
1722
+ month = liboffsets . _int_to_month [self .month ]
1734
1723
return '{prefix}-{month}' .format (prefix = self ._prefix , month = month )
1735
1724
1736
1725
@@ -1771,7 +1760,8 @@ class YearBegin(BeginMixin, YearOffset):
1771
1760
@apply_index_wraps
1772
1761
def apply_index (self , i ):
1773
1762
freq_month = 12 if self .month == 1 else self .month - 1
1774
- freqstr = 'A-{month}' .format (month = _int_to_month [freq_month ])
1763
+ month = liboffsets ._int_to_month [freq_month ]
1764
+ freqstr = 'A-{month}' .format (month = month )
1775
1765
return self ._beg_apply_index (i , freqstr )
1776
1766
1777
1767
@@ -1956,7 +1946,7 @@ def _get_suffix_prefix(self):
1956
1946
1957
1947
def get_rule_code_suffix (self ):
1958
1948
prefix = self ._get_suffix_prefix ()
1959
- month = _int_to_month [self .startingMonth ]
1949
+ month = liboffsets . _int_to_month [self .startingMonth ]
1960
1950
weekday = _int_to_weekday [self .weekday ]
1961
1951
return '{prefix}-{month}-{weekday}' .format (prefix = prefix , month = month ,
1962
1952
weekday = weekday )
@@ -1971,7 +1961,7 @@ def _parse_suffix(cls, varion_code, startingMonth_code, weekday_code):
1971
1961
raise ValueError ("Unable to parse varion_code: "
1972
1962
"{code}" .format (code = varion_code ))
1973
1963
1974
- startingMonth = _month_to_int [startingMonth_code ]
1964
+ startingMonth = liboffsets . _month_to_int [startingMonth_code ]
1975
1965
weekday = _weekday_to_int [weekday_code ]
1976
1966
1977
1967
return {"weekday" : weekday ,
0 commit comments