Skip to content

Commit 6636b36

Browse files
authored
REF: make _unpack_bool_indexer a function (#43800)
1 parent 2d27815 commit 6636b36

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

pandas/_libs/index.pyx

+21-19
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ cdef ndarray _get_bool_indexer(ndarray values, object val):
8585
_SIZE_CUTOFF = 1_000_000
8686

8787

88+
cdef _unpack_bool_indexer(ndarray[uint8_t, ndim=1, cast=True] indexer, object val):
89+
"""
90+
Possibly unpack a boolean mask to a single indexer.
91+
"""
92+
# Returns ndarray[bool] or int
93+
cdef:
94+
ndarray[intp_t, ndim=1] found
95+
int count
96+
97+
found = np.where(indexer)[0]
98+
count = len(found)
99+
100+
if count > 1:
101+
return indexer
102+
if count == 1:
103+
return int(found[0])
104+
105+
raise KeyError(val)
106+
107+
88108
@cython.freelist(32)
89109
cdef class IndexEngine:
90110

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

184204
indexer = _get_bool_indexer(self.values, val)
185-
return self._unpack_bool_indexer(indexer, val)
186-
187-
cdef _unpack_bool_indexer(self,
188-
ndarray[uint8_t, ndim=1, cast=True] indexer,
189-
object val):
190-
# Returns ndarray[bool] or int
191-
cdef:
192-
ndarray[intp_t, ndim=1] found
193-
int count
194-
195-
found = np.where(indexer)[0]
196-
count = len(found)
197-
198-
if count > 1:
199-
return indexer
200-
if count == 1:
201-
return int(found[0])
202-
203-
raise KeyError(val)
205+
return _unpack_bool_indexer(indexer, val)
204206

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

0 commit comments

Comments
 (0)