Skip to content

Commit f7e2b74

Browse files
authored
BUG: Series[dim3array] failing to raise ValueError for some Index subclasses (#31816)
1 parent 74dad82 commit f7e2b74

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ def _get_with(self, key):
919919
indexer = self.index.get_indexer_for(key)
920920
return self.iloc[indexer]
921921
else:
922-
return self._get_values(key)
922+
return self.iloc[key]
923923

924924
if isinstance(key, (list, tuple)):
925925
# TODO: de-dup with tuple case handled above?

pandas/tests/indexing/test_indexing.py

+8-23
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,18 @@ def test_getitem_ndarray_3d(self, index, obj, idxr, idxr_id):
8080
idxr = idxr(obj)
8181
nd3 = np.random.randint(5, size=(2, 2, 2))
8282

83-
msg = (
84-
r"Buffer has wrong number of dimensions \(expected 1, "
85-
r"got 3\)|"
86-
"Cannot index with multidimensional key|"
87-
r"Wrong number of dimensions. values.ndim != ndim \[3 != 1\]|"
88-
"Index data must be 1-dimensional"
83+
msg = "|".join(
84+
[
85+
r"Buffer has wrong number of dimensions \(expected 1, got 3\)",
86+
"Cannot index with multidimensional key",
87+
r"Wrong number of dimensions. values.ndim != ndim \[3 != 1\]",
88+
"Index data must be 1-dimensional",
89+
]
8990
)
9091

91-
if (
92-
isinstance(obj, Series)
93-
and idxr_id == "getitem"
94-
and index.inferred_type
95-
in [
96-
"string",
97-
"datetime64",
98-
"period",
99-
"timedelta64",
100-
"boolean",
101-
"categorical",
102-
]
103-
):
92+
with pytest.raises(ValueError, match=msg):
10493
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
10594
idxr[nd3]
106-
else:
107-
with pytest.raises(ValueError, match=msg):
108-
with tm.assert_produces_warning(DeprecationWarning):
109-
idxr[nd3]
11095

11196
@pytest.mark.parametrize(
11297
"index", tm.all_index_generator(5), ids=lambda x: type(x).__name__

0 commit comments

Comments
 (0)