Skip to content

TYP: reshape.merge #53752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,12 @@ def value_counts(

right = [diff.cumsum() - 1, codes[-1]]

_, idx = get_join_indexers(left, right, sort=False, how="left")
# error: Argument 1 to "get_join_indexers" has incompatible type
# "List[ndarray[Any, Any]]"; expected "List[Union[Union[ExtensionArray,
# ndarray[Any, Any]], Index, Series]]
_, idx = get_join_indexers(
left, right, sort=False, how="left" # type: ignore[arg-type]
)
out = np.where(idx != -1, out[idx], 0)

if sort:
Expand Down
29 changes: 14 additions & 15 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
ensure_object,
is_bool,
is_bool_dtype,
is_extension_array_dtype,
is_float_dtype,
is_integer,
is_integer_dtype,
Expand Down Expand Up @@ -1611,8 +1610,8 @@ def _validate(self, validate: str) -> None:


def get_join_indexers(
left_keys,
right_keys,
left_keys: list[AnyArrayLike],
right_keys: list[AnyArrayLike],
sort: bool = False,
how: MergeHow | Literal["asof"] = "inner",
**kwargs,
Expand All @@ -1621,8 +1620,8 @@ def get_join_indexers(

Parameters
----------
left_keys : ndarray, Index, Series
right_keys : ndarray, Index, Series
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'

Expand Down Expand Up @@ -2062,11 +2061,11 @@ def _get_merge_keys(
def _get_join_indexers(self) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:
"""return the join indexers"""

def flip(xs) -> np.ndarray:
def flip(xs: list[AnyArrayLike]) -> np.ndarray:
"""unlike np.transpose, this returns an array of tuples"""

def injection(obj):
if not is_extension_array_dtype(obj):
def injection(obj: AnyArrayLike):
if not isinstance(obj.dtype, ExtensionDtype):
# ndarray
return obj
obj = extract_array(obj)
Expand Down Expand Up @@ -2213,7 +2212,7 @@ def injection(obj):


def _get_multiindex_indexer(
join_keys, index: MultiIndex, sort: bool
join_keys: list[AnyArrayLike], index: MultiIndex, sort: bool
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:
# left & right join labels and num. of levels at each location
mapped = (
Expand Down Expand Up @@ -2250,7 +2249,7 @@ def _get_multiindex_indexer(


def _get_single_indexer(
join_key, index: Index, sort: bool = False
join_key: AnyArrayLike, index: Index, sort: bool = False
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:
left_key, right_key, count = _factorize_keys(join_key, index._values, sort=sort)

Expand Down Expand Up @@ -2295,7 +2294,7 @@ def _get_no_sort_one_missing_indexer(


def _left_join_on_index(
left_ax: Index, right_ax: Index, join_keys, sort: bool = False
left_ax: Index, right_ax: Index, join_keys: list[AnyArrayLike], sort: bool = False
) -> tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp]]:
if isinstance(right_ax, MultiIndex):
left_indexer, right_indexer = _get_multiindex_indexer(
Expand All @@ -2316,8 +2315,8 @@ def _left_join_on_index(


def _factorize_keys(
lk: ArrayLike,
rk: ArrayLike,
lk: AnyArrayLike,
rk: AnyArrayLike,
sort: bool = True,
how: MergeHow | Literal["asof"] = "inner",
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int]:
Expand All @@ -2328,9 +2327,9 @@ def _factorize_keys(

Parameters
----------
lk : array-like
lk : ndarray, ExtensionArray, Index, or Series
Left key.
rk : array-like
rk : ndarray, ExtensionArray, Index, or Series
Right key.
sort : bool, defaults to True
If True, the encoding is done such that the unique elements in the
Expand Down