Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR #48411 on branch 1.5.x (REGR: get_loc for ExtensionEngine not returning bool indexer for na) #48430

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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