Skip to content
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

TYP: Index.join #46518

Merged
merged 6 commits into from
May 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ Other Deprecations
- Deprecated passing arguments as positional in :meth:`DataFrame.any` and :meth:`Series.any` (:issue:`44802`)
- Deprecated the ``closed`` argument in :meth:`interval_range` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the methods :meth:`DataFrame.mad`, :meth:`Series.mad`, and the corresponding groupby methods (:issue:`11787`)
- Deprecated positional arguments to :meth:`Index.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`)

.. ---------------------------------------------------------------------------
.. _whatsnew_150.performance:
Expand Down
56 changes: 51 additions & 5 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
DtypeObj,
F,
IgnoreRaise,
Level,
Shape,
npt,
)
Expand Down Expand Up @@ -4529,16 +4530,53 @@ def _reindex_non_unique(
# --------------------------------------------------------------------
# Join Methods

@overload
def join(
self,
other: Index,
*,
how: str_t = ...,
level: Level = ...,
return_indexers: Literal[True],
sort: bool = ...,
) -> tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]:
...

@overload
def join(
self,
other: Index,
*,
how: str_t = ...,
level: Level = ...,
return_indexers: Literal[False] = ...,
sort: bool = ...,
) -> Index:
...

@overload
def join(
self,
other: Index,
*,
how: str_t = ...,
level: Level = ...,
return_indexers: bool = ...,
sort: bool = ...,
) -> Index | tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]:
...

@final
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "other"])
twoertwein marked this conversation as resolved.
Show resolved Hide resolved
@_maybe_return_indexers
def join(
self,
other,
other: Index,
how: str_t = "left",
level=None,
level: Level = None,
return_indexers: bool = False,
sort: bool = False,
):
) -> Index | tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]:
"""
Compute join_index and indexers to conform data
structures to the new index.
Expand Down Expand Up @@ -4723,16 +4761,24 @@ def _join_multi(self, other: Index, how: str_t):
# Join left and right
# Join on same leveled multi-index frames is supported
join_idx, lidx, ridx = self_jnlevels.join(
other_jnlevels, how, return_indexers=True
other_jnlevels, how=how, return_indexers=True
)

# Restore the dropped levels
# Returned index level order is
# common levels, ldrop_names, rdrop_names
dropped_names = ldrop_names + rdrop_names

# error: Argument 5/6 to "restore_dropped_levels_multijoin" has
# incompatible type "Optional[ndarray[Any, dtype[signedinteger[Any
# ]]]]"; expected "ndarray[Any, dtype[signedinteger[Any]]]"
levels, codes, names = restore_dropped_levels_multijoin(
self, other, dropped_names, join_idx, lidx, ridx
self,
other,
dropped_names,
join_idx,
lidx, # type: ignore[arg-type]
ridx, # type: ignore[arg-type]
)

# Re-create the multi-index
Expand Down