BUG: RangeIndex.get_indexer is incorrect for some decreasing RangeIndex #28678
Labels
Bug
Indexing
Related to indexing on series/frames, not to indexes themselves
Regression
Functionality that used to work in a prior pandas version
Milestone
For some decreasing
RangeIndex
, theget_indexer
method will indicate that all of it's own values are missing, and find matches for values not included in the index:This will in turn result in methods like
Series.reindex
not working properly:The issue appears to occur specifically for decreasing
RangeIndex
that are not in their canonical form. By canonical form, I mean whenstop
is the next valid value in the range that's not included, e.g. when you think of a more standard range likerange(1, 7, 1)
, 7 is the next valid value that's not present, but when the step is larger than 1 you lose uniqueness of representation withstop
(i.e.range(1, 6, 2) == range(1, 7, 2)
).Note that the code above works properly for the equivalent
RangeIndex
in it's canonical form:The cause of the issue appears to be that the code to determine
start
,stop
,step
when dealing with decreasingRangeIndex
inget_indexer
assumesself.stop
is the canonical form:pandas/pandas/core/indexes/range.py
Lines 386 to 390 in c4489cb
Instead of directly computing the reversed values ourselves, I think we should simply take the values from the reversed underlying
range
object:The text was updated successfully, but these errors were encountered: