After implementing a custom frequency in pandas by subclassing DateOffset, is it possible to “register” an offset alias for that frequency so that the alias can be used in built-in pandas functions such as date_range and resample?
For example, suppose I implement a custom twice-monthly frequency:
from pandas.tseries.offsets import DateOffset, CacheableOffset
class TwiceMonthly(DateOffset, CacheableOffset):
def apply(self, other):
# Some date logic here
@property
def rule_code(self):
return 'TM'
Now, instead of using TwiceMonthly() everywhere, I want to use the offset alias TM.
# Suppose s is a time series
s.resample('TM', how='sum')
That’s not possible right now unfortunately. Aliasing is static.
It would be a good feature to add though. Please check back on github (https://github.com/pydata/pandas/issues/2085). Additional feedback or a PR would be appreciated.