Skip to content

BUG: fix index validation in algos.take #27079

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

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ def take(arr, indices, axis=0, allow_fill=False, fill_value=None):

if allow_fill:
# Pandas style, -1 means NA
validate_indices(indices, len(arr))
validate_indices(indices, arr.shape[axis])
result = take_1d(arr, indices, axis=axis, allow_fill=True,
fill_value=fill_value)
else:
Expand Down
9 changes: 0 additions & 9 deletions pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,15 +1868,6 @@ def _maybe_to_dense(obj):
return obj


def _maybe_to_sparse(array):
"""
array must be SparseSeries or SparseArray
"""
if isinstance(array, ABCSparseSeries):
array = array.array.copy()
return array


def make_sparse(arr, kind='block', fill_value=None, dtype=None, copy=False):
"""
Convert ndarray to sparse format
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_take.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ def test_take_axis_1(self):
expected = np.array([[0, 0], [3, 0], [6, 0], [9, 0]])
tm.assert_numpy_array_equal(result, expected)

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


class TestExtensionTake:
# The take method found in pd.api.extensions
Expand Down