Skip to content

Commit 12b7428

Browse files
committed
BUG: Raise TypeError for scalar indexer in take
1 parent fb86932 commit 12b7428

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pandas/core/indexes/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,8 @@ def take(
10591059
):
10601060
if kwargs:
10611061
nv.validate_take((), kwargs)
1062+
if np.isscalar(indices):
1063+
raise TypeError("Expected indices to be array-like")
10621064
indices = ensure_platform_int(indices)
10631065
allow_fill = self._maybe_disallow_fill(allow_fill, fill_value, indices)
10641066

pandas/tests/indexes/test_indexing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ def test_take(self, index):
7070
with pytest.raises(AttributeError, match=msg):
7171
index.freq
7272

73+
def test_take_indexer_type(self):
74+
integer_index = Int64Index([0, 1, 2, 3])
75+
scalar_index = 1
76+
msg = "Expected indices to be array-like"
77+
with pytest.raises(TypeError, match=msg):
78+
integer_index.take(scalar_index)
79+
7380
def test_take_minus1_without_fill(self, index):
7481
# -1 does not get treated as NA unless allow_fill=True is passed
7582
if len(index) == 0:

0 commit comments

Comments
 (0)