Skip to content

Commit 58c124f

Browse files
authored
REGR: get_loc for ExtensionEngine not returning bool indexer for na (#48411)
1 parent 50c119d commit 58c124f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pandas/_libs/index.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ cdef class ExtensionEngine(SharedEngine):
10611061

10621062
cdef ndarray _get_bool_indexer(self, val):
10631063
if checknull(val):
1064-
return self.values.isna().view("uint8")
1064+
return self.values.isna()
10651065

10661066
try:
10671067
return self.values == val

pandas/tests/indexes/test_indexing.py

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from pandas.errors import InvalidIndexError
2121

2222
from pandas import (
23+
NA,
2324
DatetimeIndex,
2425
Index,
2526
IntervalIndex,
@@ -221,6 +222,13 @@ def test_get_loc_generator(self, index):
221222
# MultiIndex specifically checks for generator; others for scalar
222223
index.get_loc(x for x in range(5))
223224

225+
def test_get_loc_masked_duplicated_na(self):
226+
# GH#48411
227+
idx = Index([1, 2, NA, NA], dtype="Int64")
228+
result = idx.get_loc(NA)
229+
expected = np.array([False, False, True, True])
230+
tm.assert_numpy_array_equal(result, expected)
231+
224232

225233
class TestGetIndexer:
226234
def test_get_indexer_base(self, index):
@@ -253,6 +261,13 @@ def test_get_indexer_consistency(self, index):
253261
assert isinstance(indexer, np.ndarray)
254262
assert indexer.dtype == np.intp
255263

264+
def test_get_indexer_masked_duplicated_na(self):
265+
# GH#48411
266+
idx = Index([1, 2, NA, NA], dtype="Int64")
267+
result = idx.get_indexer_for(Index([1, NA], dtype="Int64"))
268+
expected = np.array([0, 2, 3], dtype=result.dtype)
269+
tm.assert_numpy_array_equal(result, expected)
270+
256271

257272
class TestConvertSliceIndexer:
258273
def test_convert_almost_null_slice(self, index):

0 commit comments

Comments
 (0)