Index.add OK but sub not? (original) (raw)
Curious about why Index.__add__ tries does the natural thing but Index.__sub__ raises TypeError.
def __add__(self, other):
return Index(np.array(self) + other)
def __radd__(self, other):
return Index(other + np.array(self))
__iadd__ = __add__
def __sub__(self, other):
raise TypeError("cannot perform __sub__ with this index type: "
"{typ}".format(typ=type(self)))