diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index b12c8830f15ab..0b11860848ac0 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -270,11 +270,11 @@ cdef class IndexEngine: Py_ssize_t i, j, n, n_t, n_alloc self._ensure_mapping_populated() - if isnaobj(targets).any(): + if targets[isnaobj(targets)].size > 0: new_targets = [0 if checknull(t) else t for t in targets] new_values = [0 if checknull(v) else v for v in self._get_index_values()] - targets = np.array(new_targets, dtype=object) - values = np.array(new_values, dtype=object) + targets = np.array(new_targets, dtype=targets.dtype) + values = np.array(new_values, dtype=self._get_index_values().dtype) else: values = np.array(self._get_index_values(), copy=False)