

def _reindex_non_unique(self, target):
    "\n        *this is an internal non-public method*\n\n        Create a new index with target's values (move/add/delete values as\n        necessary) use with non-unique Index and a possibly non-unique target\n\n        Parameters\n        ----------\n        target : an iterable\n\n        Returns\n        -------\n        new_index : pd.Index\n            Resulting index\n        indexer : np.ndarray or None\n            Indices of output values in original index\n\n        "
    target = _ensure_index(target)
    (indexer, missing) = self.get_indexer_non_unique(target)
    check = (indexer != (- 1))
    new_labels = self.take(indexer[check])
    new_indexer = None
    if len(missing):
        l = np.arange(len(indexer))
        missing = com._ensure_platform_int(missing)
        missing_labels = target.take(missing)
        missing_indexer = _ensure_int64(l[(~ check)])
        cur_labels = self.take(indexer[check])._values
        cur_indexer = _ensure_int64(l[check])
        new_labels = np.empty(tuple([len(indexer)]), dtype=object)
        new_labels[cur_indexer] = cur_labels
        new_labels[missing_indexer] = missing_labels
        if target.is_unique:
            new_indexer = np.arange(len(indexer))
            new_indexer[cur_indexer] = np.arange(len(cur_labels))
            new_indexer[missing_indexer] = (- 1)
        else:
            indexer = indexer._values
            indexer[(~ check)] = 0
            new_indexer = np.arange(len(self.take(indexer)))
            new_indexer[(~ check)] = (- 1)
    new_index = self._shallow_copy_with_infer(new_labels, freq=None)
    return (new_index, indexer, new_indexer)

dataset/ETHPy150Open pydata/pandas/pandas/indexes/base.py Index._reindex_non_unique/original