MCPcopy
hub / github.com/pandas-dev/pandas / get_indexer_non_unique

Method get_indexer_non_unique

pandas/core/indexes/base.py:6161–6250  ·  view source on GitHub ↗

Compute indexer and mask for new index given the current index. The indexer should be then used as an input to ndarray.take to align the current data to the new index. Parameters ---------- target : Index An iterable containing the value

(
        self, target
    )

Source from the content-addressed store, hash-verified

6159 """
6160
6161 def get_indexer_non_unique(
6162 self, target
6163 ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:
6164 """
6165 Compute indexer and mask for new index given the current index.
6166
6167 The indexer should be then used as an input to ndarray.take to align the
6168 current data to the new index.
6169
6170 Parameters
6171 ----------
6172 target : Index
6173 An iterable containing the values to be used for computing indexer.
6174
6175 Returns
6176 -------
6177 indexer : np.ndarray[np.intp]
6178 Integers from 0 to n - 1 indicating that the index at these
6179 positions matches the corresponding target values. Missing values
6180 in the target are marked by -1.
6181 missing : np.ndarray[np.intp]
6182 An indexer into the target of the values not found.
6183 These correspond to the -1 in the indexer array.
6184
6185 See Also
6186 --------
6187 Index.get_indexer : Computes indexer and mask for new index given
6188 the current index.
6189 Index.get_indexer_for : Returns an indexer even when non-unique.
6190
6191 Examples
6192 --------
6193 >>> index = pd.Index(["c", "b", "a", "b", "b"])
6194 >>> index.get_indexer_non_unique(["b", "b"])
6195 (array([1, 3, 4, 1, 3, 4]), array([], dtype=int64))
6196
6197 In the example below there are no matched values.
6198
6199 >>> index = pd.Index(["c", "b", "a", "b", "b"])
6200 >>> index.get_indexer_non_unique(["q", "r", "t"])
6201 (array([-1, -1, -1]), array([0, 1, 2]))
6202
6203 For this reason, the returned ``indexer`` contains only integers equal to -1.
6204 It demonstrates that there's no match between the index and the ``target``
6205 values at these positions. The mask [0, 1, 2] in the return value shows that
6206 the first, second, and third elements are missing.
6207
6208 Notice that the return value is a tuple contains two items. In the example
6209 below the first item is an array of locations in ``index``. The second
6210 item is a mask shows that the first and third elements are missing.
6211
6212 >>> index = pd.Index(["c", "b", "a", "b", "b"])
6213 >>> index.get_indexer_non_unique(["f", "b", "s"])
6214 (array([-1, 1, 3, 4, -1]), array([0, 2]))
6215 """
6216 target = self._maybe_cast_listlike_indexer(target)
6217
6218 if not self._should_compare(target) and not self._should_partial_index(target):

Calls 8

_should_compareMethod · 0.95
_should_partial_indexMethod · 0.95
astypeMethod · 0.95
_get_engine_targetMethod · 0.45