-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: fix index op names and pinning #19723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
e20da51
885dd68
25af8eb
c5fdf53
a68826d
eb23db0
c3d9d9f
ef845af
88c9638
ba2d4ca
5773fd8
f6412e5
f2e852c
4c5e54f
0824382
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,6 +669,7 @@ def __add__(self, other): | |
return self._add_offset_array(other) | ||
elif isinstance(self, TimedeltaIndex) and isinstance(other, Index): | ||
if hasattr(other, '_add_delta'): | ||
# i.e. DatetimeIndex, TimedeltaIndex, or PeriodIndex | ||
return other._add_delta(self) | ||
raise TypeError("cannot add TimedeltaIndex and {typ}" | ||
.format(typ=type(other))) | ||
|
@@ -685,7 +686,11 @@ def __add__(self, other): | |
return NotImplemented | ||
|
||
cls.__add__ = __add__ | ||
cls.__radd__ = __add__ | ||
|
||
def __radd__(self, other): | ||
# alias for __add__ | ||
return self.__add__(other) | ||
cls.__radd__ = __radd__ | ||
|
||
def __sub__(self, other): | ||
from pandas.core.index import Index | ||
|
@@ -704,10 +709,11 @@ def __sub__(self, other): | |
# Array/Index of DateOffset objects | ||
return self._sub_offset_array(other) | ||
elif isinstance(self, TimedeltaIndex) and isinstance(other, Index): | ||
if not isinstance(other, TimedeltaIndex): | ||
raise TypeError("cannot subtract TimedeltaIndex and {typ}" | ||
.format(typ=type(other).__name__)) | ||
return self._add_delta(-other) | ||
assert not is_timedelta64_dtype(other) | ||
# We checked above for timedelta64_dtype(other) so this | ||
# must be invalid. | ||
raise TypeError("cannot subtract TimedeltaIndex and {typ}" | ||
.format(typ=type(other).__name__)) | ||
elif isinstance(other, DatetimeIndex): | ||
return self._sub_datelike(other) | ||
elif is_integer(other): | ||
|
@@ -732,8 +738,15 @@ def __rsub__(self, other): | |
return -(self - other) | ||
cls.__rsub__ = __rsub__ | ||
|
||
cls.__iadd__ = __add__ | ||
cls.__isub__ = __sub__ | ||
def __iadd__(self, other): | ||
# alias for __add__ | ||
return self.__add__(other) | ||
cls.__iadd__ = __iadd__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this double assignment ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we just set |
||
|
||
def __isub__(self, other): | ||
# alias for __sub__ | ||
return self.__sub__(other) | ||
cls.__isub__ = __isub__ | ||
|
||
def _add_delta(self, other): | ||
return NotImplemented | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove.