Skip to content

Commit 29bc3c3

Browse files
committed
BUG: fix algos.take index validation, closes pandas-dev#26976
1 parent e955515 commit 29bc3c3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ def take(arr, indices, axis=0, allow_fill=False, fill_value=None):
15261526

15271527
if allow_fill:
15281528
# Pandas style, -1 means NA
1529-
validate_indices(indices, len(arr))
1529+
validate_indices(indices, arr.shape[axis])
15301530
result = take_1d(arr, indices, axis=axis, allow_fill=True,
15311531
fill_value=fill_value)
15321532
else:

pandas/tests/test_take.py

+5
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ def test_take_axis_1(self):
420420
expected = np.array([[0, 0], [3, 0], [6, 0], [9, 0]])
421421
tm.assert_numpy_array_equal(result, expected)
422422

423+
# GH#26976 make sure we validate along the correct axis
424+
with pytest.raises(IndexError, match="indices are out-of-bounds"):
425+
algos.take(arr, [0, 3], axis=1, allow_fill=True,
426+
fill_value=0)
427+
423428

424429
class TestExtensionTake:
425430
# The take method found in pd.api.extensions

0 commit comments

Comments
 (0)