-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: intersection of decreasing RangeIndexes #17374
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
Conversation
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -359,6 +359,7 @@ Indexing | |||
- Bug in ``.iloc`` when used with inplace addition or assignment and an int indexer on a ``MultiIndex`` causing the wrong indexes to be read from and written to (:issue:`17148`) | |||
- Bug in ``.isin()`` in which checking membership in empty ``Series`` objects raised an error (:issue:`16991`) | |||
- Bug in ``CategoricalIndex`` reindexing in which specified indices containing duplicates were not being respected (:issue:`17323`) | |||
- Bug in intersection of ``RangeIndex``es with negative step (:issue:`17296`) |
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.
Drop the "es" in front of RangeIndex
pandas/tests/indexes/test_range.py
Outdated
@@ -609,6 +609,19 @@ def test_intersection(self): | |||
expected = Index(np.sort(np.intersect1d(self.index.values, | |||
other.values))) | |||
tm.assert_index_equal(result, expected) | |||
# reversed |
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.
Reference the issue number.
fd46d82
to
8d2038c
Compare
pandas/core/indexes/range.py
Outdated
@@ -544,6 +548,14 @@ def __floordiv__(self, other): | |||
fastpath=True) | |||
return self._int64index // other | |||
|
|||
def _reverse(self): |
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 already defined in terms of slicing, i.e. RangeIndex(...)[::-1]
will return a RangeIndex
with the opposite step and is performant.
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.
Aha, nice, thanks!
Codecov Report
@@ Coverage Diff @@
## master #17374 +/- ##
==========================================
- Coverage 91.01% 90.99% -0.02%
==========================================
Files 163 163
Lines 49567 49574 +7
==========================================
- Hits 45113 45111 -2
- Misses 4454 4463 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17374 +/- ##
==========================================
- Coverage 91.15% 91.14% -0.02%
==========================================
Files 163 163
Lines 49587 49591 +4
==========================================
- Hits 45203 45198 -5
- Misses 4384 4393 +9
Continue to review full report at Codecov.
|
FYI: I had to mark a test as xfailing in #17272 due to this bug. The PR is still open, but depending on when it gets merged you may need to rebase and remove the xfail. |
8d2038c
to
680dd4b
Compare
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.
very minor comment. ping on green.
pandas/tests/indexes/test_range.py
Outdated
expected = first.astype(int).intersection(other.astype(int)) | ||
result = first.intersection(other).astype(int) | ||
tm.assert_index_equal(result, expected) | ||
# reversed |
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.
can you put blank line here
pandas/tests/indexes/test_range.py
Outdated
@@ -609,6 +609,19 @@ def test_intersection(self): | |||
expected = Index(np.sort(np.intersect1d(self.index.values, | |||
other.values))) | |||
tm.assert_index_equal(result, expected) | |||
# reversed (GH 17296) |
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.
here as well
680dd4b
to
cc0bd29
Compare
@jreback ping |
lgtm. can you rebase and ping on green just to make sure. |
cc0bd29
to
457e7ff
Compare
@jreback ping |
thanks! |
git diff master -u -- "*.py" | flake8 --diff