Skip to content

REF: make _unpack_bool_indexer a function #43800

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

Merged
merged 2 commits into from
Sep 30, 2021
Merged
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
40 changes: 21 additions & 19 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ cdef ndarray _get_bool_indexer(ndarray values, object val):
_SIZE_CUTOFF = 1_000_000


cdef _unpack_bool_indexer(ndarray[uint8_t, ndim=1, cast=True] indexer, object val):
"""
Possibly unpack a boolean mask to a single indexer.
"""
# Returns ndarray[bool] or int
cdef:
ndarray[intp_t, ndim=1] found
int count

found = np.where(indexer)[0]
count = len(found)

if count > 1:
return indexer
if count == 1:
return int(found[0])

raise KeyError(val)


@cython.freelist(32)
cdef class IndexEngine:

Expand Down Expand Up @@ -182,25 +202,7 @@ cdef class IndexEngine:
ndarray[uint8_t, ndim=1, cast=True] indexer

indexer = _get_bool_indexer(self.values, val)
return self._unpack_bool_indexer(indexer, val)

cdef _unpack_bool_indexer(self,
ndarray[uint8_t, ndim=1, cast=True] indexer,
object val):
# Returns ndarray[bool] or int
cdef:
ndarray[intp_t, ndim=1] found
int count

found = np.where(indexer)[0]
count = len(found)

if count > 1:
return indexer
if count == 1:
return int(found[0])

raise KeyError(val)
return _unpack_bool_indexer(indexer, val)

def sizeof(self, deep: bool = False) -> int:
""" return the sizeof our mapping """
Expand Down