Skip to content

Commit

Permalink
Backport PR pandas-dev#48411: REGR: get_loc for ExtensionEngine not r…
Browse files Browse the repository at this point in the history
…eturning bool indexer for na
  • Loading branch information
phofl authored and meeseeksmachine committed Sep 7, 2022
1 parent e6f5022 commit 750f27b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ cdef class ExtensionEngine(SharedEngine):

cdef ndarray _get_bool_indexer(self, val):
if checknull(val):
return self.values.isna().view("uint8")
return self.values.isna()

try:
return self.values == val
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/indexes/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pandas.errors import InvalidIndexError

from pandas import (
NA,
DatetimeIndex,
Index,
IntervalIndex,
Expand Down Expand Up @@ -221,6 +222,13 @@ def test_get_loc_generator(self, index):
# MultiIndex specifically checks for generator; others for scalar
index.get_loc(x for x in range(5))

def test_get_loc_masked_duplicated_na(self):
# GH#48411
idx = Index([1, 2, NA, NA], dtype="Int64")
result = idx.get_loc(NA)
expected = np.array([False, False, True, True])
tm.assert_numpy_array_equal(result, expected)


class TestGetIndexer:
def test_get_indexer_base(self, index):
Expand Down Expand Up @@ -253,6 +261,13 @@ def test_get_indexer_consistency(self, index):
assert isinstance(indexer, np.ndarray)
assert indexer.dtype == np.intp

def test_get_indexer_masked_duplicated_na(self):
# GH#48411
idx = Index([1, 2, NA, NA], dtype="Int64")
result = idx.get_indexer_for(Index([1, NA], dtype="Int64"))
expected = np.array([0, 2, 3], dtype=result.dtype)
tm.assert_numpy_array_equal(result, expected)


class TestConvertSliceIndexer:
def test_convert_almost_null_slice(self, index):
Expand Down

0 comments on commit 750f27b

Please sign in to comment.