-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: fix index op names and pinning #19723
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19723 +/- ##
==========================================
+ Coverage 91.57% 91.58% +0.01%
==========================================
Files 150 150
Lines 48903 48890 -13
==========================================
- Hits 44785 44778 -7
+ Misses 4118 4112 -6
Continue to review full report at Codecov.
|
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.
so leave out the rsub changes for now. the refactor part is ok
pandas/core/indexes/datetimelike.py
Outdated
raise TypeError("cannot subtract TimedeltaIndex and {typ}" | ||
.format(typ=type(other).__name__)) | ||
return self._add_delta(-other) | ||
assert not is_timedelta64_dtype(other) |
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.
its also not clear the changes are actually being tested. |
The added parameters in tests.indexes.test_base test the relevant changes here. That test would fail under the status-quo. |
OK. That will require special-casing to escape that case in tests.indexes.test_base; we can revisit later. |
This one isn’t particularly conducive to splitting into smaller parts, but I could try if that’ll help. |
pandas/tests/indexes/test_base.py
Outdated
def test_generated_op_names(opname, indices): | ||
index = indices | ||
if type(index) is pd.Index and opname == 'rsub': |
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.
use isinstance, or is this a very specific check if some is NOT a Index. maybe better to use ABCIndex and/or ABCIndexClass
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 specific to pd.Index, not subclasses.
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.
pls change this
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.
need some tests for iadd/isub, in particular
#17067 (2 things going on in that issue(
e.g.
s = pd.Series([1, 2, 3])
s.index.name = "foo"
s.index += 1
assert s.index.name == "foo"
The reset_index thing looks unrelated. Am I reading it wrong? |
the reset_index is unrelated |
This may be all set. |
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
If we just set cls.__iadd__ = __add__
then when we check for Index.__iadd__.__name__
we'll get __add__
instead of __iadd__
. Not a big deal, but its cheap to make it pretty.
pandas/tests/indexes/test_base.py
Outdated
def test_generated_op_names(opname, indices): | ||
index = indices | ||
if type(index) is pd.Index and opname == 'rsub': |
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.
pls change this
Sure, to |
I for one didn't know (and wouldn't know directly from reading code, and find it also surprising) that |
But I have to agree it is clear from the abc code (I just don't interact much with that part of the code base that needs to use ABCs). I only intuitively would have expected the names to be the other way around :-) |
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.
Does this need a whatsnew note?
I guess its technically user-facing, but it seems like it would be mostly clutter. I'm fine either way. |
needs a rebase |
I messed up most recent merge, will fix in AM. |
lgtm. ping on green. (I think just appeveyor left). |
ping |
thanks |
This is a moderately big one, but changes very little.
Fixes incorrect Index ops names and several methods that are defined but not pinned to the class (#19716).
Avoids the need to pass
reversed
andstr_rep
in a bunch of places, cleans up some of the Index classmethods.Removes the no-longer-needed catching of AttributeError in RangeIndex ops.
The part that may be controversial (and almost certainly needs new tests) is that
Index.__rsub__
is implemented, since it doesn't currently exist. This implements it in "the obvious way", but the fact thatIndex.__sub__
isn't defined in the obvious way suggests this might not be desired. Comments welcome.git diff upstream/master -u -- "*.py" | flake8 --diff