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

Function get_join_indexers

pandas/core/reshape/merge.py:2043–2118  ·  view source on GitHub ↗

Parameters ---------- left_keys : list[ndarray, ExtensionArray, Index, Series] right_keys : list[ndarray, ExtensionArray, Index, Series] sort : bool, default False how : {'inner', 'outer', 'left', 'right'}, default 'inner' Returns ------- np.ndarray[np.intp] or

(
    left_keys: list[ArrayLike],
    right_keys: list[ArrayLike],
    sort: bool = False,
    how: JoinHow = "inner",
)

Source from the content-addressed store, hash-verified

2041
2042
2043def get_join_indexers(
2044 left_keys: list[ArrayLike],
2045 right_keys: list[ArrayLike],
2046 sort: bool = False,
2047 how: JoinHow = "inner",
2048) -> tuple[npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]:
2049 """
2050
2051 Parameters
2052 ----------
2053 left_keys : list[ndarray, ExtensionArray, Index, Series]
2054 right_keys : list[ndarray, ExtensionArray, Index, Series]
2055 sort : bool, default False
2056 how : {'inner', 'outer', 'left', 'right'}, default 'inner'
2057
2058 Returns
2059 -------
2060 np.ndarray[np.intp] or None
2061 Indexer into the left_keys.
2062 np.ndarray[np.intp] or None
2063 Indexer into the right_keys.
2064 """
2065 assert len(left_keys) == len(right_keys), (
2066 "left_keys and right_keys must be the same length"
2067 )
2068
2069 # fast-path for empty left/right
2070 left_n = len(left_keys[0])
2071 right_n = len(right_keys[0])
2072 if left_n == 0:
2073 if how in ["left", "inner"]:
2074 return _get_empty_indexer()
2075 elif not sort and how in ["right", "outer"]:
2076 return _get_no_sort_one_missing_indexer(right_n, True)
2077 elif right_n == 0:
2078 if how in ["right", "inner"]:
2079 return _get_empty_indexer()
2080 elif not sort and how in ["left", "outer"]:
2081 return _get_no_sort_one_missing_indexer(left_n, False)
2082
2083 lkey: ArrayLike
2084 rkey: ArrayLike
2085 if len(left_keys) > 1:
2086 # get left & right join labels and num. of levels at each location
2087 mapped = (
2088 _factorize_keys(left_keys[n], right_keys[n], sort=sort)
2089 for n in range(len(left_keys))
2090 )
2091 zipped = zip(*mapped, strict=True)
2092 llab, rlab, shape = (list(x) for x in zipped)
2093
2094 # get flat i8 keys from label lists
2095 lkey, rkey = _get_join_keys(llab, rlab, tuple(shape), sort)
2096 else:
2097 lkey = left_keys[0]
2098 rkey = right_keys[0]
2099
2100 left = Index(lkey, copy=False)

Callers 2

value_countsMethod · 0.90
_get_join_indexersMethod · 0.85

Calls 7

joinMethod · 0.95
IndexClass · 0.90
_get_empty_indexerFunction · 0.85
_factorize_keysFunction · 0.85
_get_join_keysFunction · 0.85

Tested by

no test coverage detected