Skip to content

Commit 0d8f588

Browse files
authored
TYP: Index.join (#46518)
1 parent ddb315f commit 0d8f588

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ Other Deprecations
527527
- Deprecated passing arguments as positional in :meth:`DataFrame.any` and :meth:`Series.any` (:issue:`44802`)
528528
- Deprecated the ``closed`` argument in :meth:`interval_range` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
529529
- Deprecated the methods :meth:`DataFrame.mad`, :meth:`Series.mad`, and the corresponding groupby methods (:issue:`11787`)
530+
- Deprecated positional arguments to :meth:`Index.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`)
530531

531532
.. ---------------------------------------------------------------------------
532533
.. _whatsnew_150.performance:

pandas/core/indexes/base.py

+51-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
DtypeObj,
4949
F,
5050
IgnoreRaise,
51+
Level,
5152
Shape,
5253
npt,
5354
)
@@ -4529,16 +4530,53 @@ def _reindex_non_unique(
45294530
# --------------------------------------------------------------------
45304531
# Join Methods
45314532

4533+
@overload
4534+
def join(
4535+
self,
4536+
other: Index,
4537+
*,
4538+
how: str_t = ...,
4539+
level: Level = ...,
4540+
return_indexers: Literal[True],
4541+
sort: bool = ...,
4542+
) -> tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]:
4543+
...
4544+
4545+
@overload
4546+
def join(
4547+
self,
4548+
other: Index,
4549+
*,
4550+
how: str_t = ...,
4551+
level: Level = ...,
4552+
return_indexers: Literal[False] = ...,
4553+
sort: bool = ...,
4554+
) -> Index:
4555+
...
4556+
4557+
@overload
4558+
def join(
4559+
self,
4560+
other: Index,
4561+
*,
4562+
how: str_t = ...,
4563+
level: Level = ...,
4564+
return_indexers: bool = ...,
4565+
sort: bool = ...,
4566+
) -> Index | tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]:
4567+
...
4568+
45324569
@final
4570+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "other"])
45334571
@_maybe_return_indexers
45344572
def join(
45354573
self,
4536-
other,
4574+
other: Index,
45374575
how: str_t = "left",
4538-
level=None,
4576+
level: Level = None,
45394577
return_indexers: bool = False,
45404578
sort: bool = False,
4541-
):
4579+
) -> Index | tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]:
45424580
"""
45434581
Compute join_index and indexers to conform data
45444582
structures to the new index.
@@ -4723,16 +4761,24 @@ def _join_multi(self, other: Index, how: str_t):
47234761
# Join left and right
47244762
# Join on same leveled multi-index frames is supported
47254763
join_idx, lidx, ridx = self_jnlevels.join(
4726-
other_jnlevels, how, return_indexers=True
4764+
other_jnlevels, how=how, return_indexers=True
47274765
)
47284766

47294767
# Restore the dropped levels
47304768
# Returned index level order is
47314769
# common levels, ldrop_names, rdrop_names
47324770
dropped_names = ldrop_names + rdrop_names
47334771

4772+
# error: Argument 5/6 to "restore_dropped_levels_multijoin" has
4773+
# incompatible type "Optional[ndarray[Any, dtype[signedinteger[Any
4774+
# ]]]]"; expected "ndarray[Any, dtype[signedinteger[Any]]]"
47344775
levels, codes, names = restore_dropped_levels_multijoin(
4735-
self, other, dropped_names, join_idx, lidx, ridx
4776+
self,
4777+
other,
4778+
dropped_names,
4779+
join_idx,
4780+
lidx, # type: ignore[arg-type]
4781+
ridx, # type: ignore[arg-type]
47364782
)
47374783

47384784
# Re-create the multi-index

0 commit comments

Comments
 (0)