Skip to content
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Interval
Indexing
^^^^^^^^

-
- Fix regression in :meth:`DataFrame.reindex` not following ``limit`` argument (:issue:`28631`).
-
-

Expand Down
11 changes: 9 additions & 2 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,15 @@ def get_loc(self, key, method=None, tolerance=None):

@Appender(_index_shared_docs["get_indexer"])
def get_indexer(self, target, method=None, limit=None, tolerance=None):
if not (method is None and tolerance is None and is_list_like(target)):
return super().get_indexer(target, method=method, tolerance=tolerance)
if not (
method is None
and tolerance is None
and limit is None
and is_list_like(target)
):
return super().get_indexer(
target, method=method, tolerance=tolerance, limit=limit
)

if self.step > 0:
start, stop, step = self.start, self.stop, self.step
Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/indexes/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,3 +1037,27 @@ def test_engineless_lookup(self):
assert idx.get_loc("a") == -1

assert "_engine" in idx._cache

def test_reindex_limit(self):
# GH 28631
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn’t belong here
rather with other dataframe reindex tests

look in tests/frame

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, move to tests/frame/test_indexing

data = [["A", "A", "A"], ["B", "B", "B"], ["C", "C", "C"], ["D", "D", "D"]]
exp_data = [
["A", "A", "A"],
["B", "B", "B"],
["C", "C", "C"],
["D", "D", "D"],
["D", "D", "D"],
[np.nan, np.nan, np.nan],
]
df = pd.DataFrame(data)
result = df.reindex([0, 1, 2, 3, 4, 5], method="ffill", limit=1)
expected = pd.DataFrame(exp_data)
tm.assert_frame_equal(result, expected)

def test_get_indexer_limit(self):
# GH 28631
idx = RangeIndex(0, 4)
target = RangeIndex(0, 6)
result = idx.get_indexer(target, method="pad", limit=1)
expected = np.array([0, 1, 2, 3, 3, -1])
tm.assert_numpy_array_equal(result, expected, check_dtype=False)