I have the following code for a custom offset class of market holidays. For some reason though I can not subtract an offset. Addition works fine. Can someone spot the error?
from pandas.tseries.offsets import CustomBusinessDay
from pandas.tseries.holiday import get_calendar, HolidayCalendarFactory, GoodFriday
class Holiday_offset:
'''
creates an offset for market holidays so that the object that is returned
may be added or subtracted to a datetime object to move 1 day forward or
back account for holidays and business days.
'''
def __init__(self):
self.cal = get_calendar('USFederalHolidayCalendar') # Create calendar instance
self.cal.rules.pop(7) # Remove Veteran's Day rule
self.cal.rules.pop(6) # Remove Columbus Day rule
self.tradingCal = HolidayCalendarFactory('TradingCalendar', self.cal, GoodFriday)
#new instance of class return as an offset object
self.offset = CustomBusinessDay(calendar=self.tradingCal())
def __add__(self,other):
return self.offset + other
def __radd__(self,other):
return self.offset + other
def __iadd__(self,other):
return self.offset + other
def __sub__(self,other):
return self.offset - other
def __rsub__(self,other):
return self.offset - other
def __isub__(self,other):
return self.offset - other
def __index__(self,other):
TypeError: Cannot subtract datetime from offset