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

Method get_indexer_non_unique

pandas/core/indexes/interval.py:853–933  ·  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 : IntervalIndex or list of Intervals An

(
        self, target: Index
    )

Source from the content-addressed store, hash-verified

851 return ensure_platform_int(indexer)
852
853 def get_indexer_non_unique(
854 self, target: Index
855 ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:
856 """
857 Compute indexer and mask for new index given the current index.
858
859 The indexer should be then used as an input to ndarray.take to align the
860 current data to the new index.
861
862 Parameters
863 ----------
864 target : IntervalIndex or list of Intervals
865 An iterable containing the values to be used for computing indexer.
866
867 Returns
868 -------
869 indexer : np.ndarray[np.intp]
870 Integers from 0 to n - 1 indicating that the index at these
871 positions matches the corresponding target values. Missing values
872 in the target are marked by -1.
873 missing : np.ndarray[np.intp]
874 An indexer into the target of the values not found.
875 These correspond to the -1 in the indexer array.
876
877 See Also
878 --------
879 Index.get_indexer : Computes indexer and mask for new index given
880 the current index.
881 Index.get_indexer_for : Returns an indexer even when non-unique.
882
883 Examples
884 --------
885 >>> index = pd.Index(["c", "b", "a", "b", "b"])
886 >>> index.get_indexer_non_unique(["b", "b"])
887 (array([1, 3, 4, 1, 3, 4]), array([], dtype=int64))
888
889 In the example below there are no matched values.
890
891 >>> index = pd.Index(["c", "b", "a", "b", "b"])
892 >>> index.get_indexer_non_unique(["q", "r", "t"])
893 (array([-1, -1, -1]), array([0, 1, 2]))
894
895 For this reason, the returned ``indexer`` contains only integers equal to -1.
896 It demonstrates that there's no match between the index and the ``target``
897 values at these positions. The mask [0, 1, 2] in the return value shows that
898 the first, second, and third elements are missing.
899
900 Notice that the return value is a tuple contains two items. In the example
901 below the first item is an array of locations in ``index``. The second
902 item is a mask shows that the first and third elements are missing.
903
904 >>> index = pd.Index(["c", "b", "a", "b", "b"])
905 >>> index.get_indexer_non_unique(["f", "b", "s"])
906 (array([-1, 1, 3, 4, -1]), array([0, 2]))
907 """
908 target = ensure_index(target)
909
910 if not self._should_compare(target) and not self._should_partial_index(target):

Callers

nothing calls this directly

Calls 9

_maybe_convert_i8Method · 0.95
ensure_indexFunction · 0.90
is_object_dtypeFunction · 0.90
_should_compareMethod · 0.80
_should_partial_indexMethod · 0.80
nonzeroMethod · 0.80

Tested by

no test coverage detected