Skip to content

Commit 8324081

Browse files
authored
BUG: Series[uintarray] failing to raise KeyError (#37495)
* CI: 32 bit maybe_indices_to_slice * accept either * revert * troubleshoot * try again * intp * multiindex np.intp * revert branched from wrong branch * BUG: Series[uint8array] failing to raise KeyError * use fixture
1 parent 6611ea7 commit 8324081

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ Indexing
441441
- Bug in :meth:`DataFrame.__getitem__` and :meth:`DataFrame.loc.__getitem__` with :class:`IntervalIndex` columns and a numeric indexer (:issue:`26490`)
442442
- Bug in :meth:`Series.loc.__getitem__` with a non-unique :class:`MultiIndex` and an empty-list indexer (:issue:`13691`)
443443
- Bug in indexing on a :class:`Series` or :class:`DataFrame` with a :class:`MultiIndex` with a level named "0" (:issue:`37194`)
444+
- Bug in :meth:`Series.__getitem__` when using an unsigned integer array as an indexer giving incorrect results or segfaulting instead of raising ``KeyError`` (:issue:`37218`)
444445

445446
Missing
446447
^^^^^^^

pandas/core/indexes/range.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
ensure_python_int,
1818
is_float,
1919
is_integer,
20-
is_integer_dtype,
2120
is_list_like,
2221
is_scalar,
22+
is_signed_integer_dtype,
2323
is_timedelta64_dtype,
2424
)
2525
from pandas.core.dtypes.generic import ABCTimedeltaIndex
@@ -369,7 +369,7 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
369369
start, stop, step = reverse.start, reverse.stop, reverse.step
370370

371371
target_array = np.asarray(target)
372-
if not (is_integer_dtype(target_array) and target_array.ndim == 1):
372+
if not (is_signed_integer_dtype(target_array) and target_array.ndim == 1):
373373
# checks/conversions/roundings are delegated to general method
374374
return super().get_indexer(target, method=method, tolerance=tolerance)
375375

pandas/tests/series/indexing/test_getitem.py

+10
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ def test_getitem_intlist_multiindex_numeric_level(self, dtype, box):
160160
with pytest.raises(KeyError, match="5"):
161161
ser[key]
162162

163+
def test_getitem_uint_array_key(self, uint_dtype):
164+
# GH #37218
165+
ser = Series([1, 2, 3])
166+
key = np.array([4], dtype=uint_dtype)
167+
168+
with pytest.raises(KeyError, match="4"):
169+
ser[key]
170+
with pytest.raises(KeyError, match="4"):
171+
ser.loc[key]
172+
163173

164174
class TestGetitemBooleanMask:
165175
def test_getitem_boolean(self, string_series):

0 commit comments

Comments
 (0)