From ebb4d6205c3622ccd17562cb85a3029353d5b5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 25 Mar 2022 21:45:21 -0400 Subject: [PATCH 1/4] TYP: Index.join --- pandas/core/indexes/base.py | 54 ++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 2ded3c4926f6b..fc37381e053c8 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -48,6 +48,7 @@ DtypeObj, F, IgnoreRaise, + Level, Shape, npt, ) @@ -4529,16 +4530,53 @@ def _reindex_non_unique( # -------------------------------------------------------------------- # Join Methods + @overload + def join( + self, + other, + *, + 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, + *, + how: str_t = ..., + level: Level = ..., + return_indexers: Literal[False] = ..., + sort: bool = ..., + ) -> Index: + ... + + @overload + def join( + self, + other, + *, + 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"]) @_maybe_return_indexers def join( self, other, 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. @@ -4723,7 +4761,7 @@ 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 @@ -4731,8 +4769,16 @@ def _join_multi(self, other: Index, how: str_t): # 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 From 74e61a1135db1baf10cc4af3aebbb0548eac6096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 31 Mar 2022 18:40:12 -0400 Subject: [PATCH 2/4] type other --- pandas/core/indexes/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fc37381e053c8..22906516b5123 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4533,7 +4533,7 @@ def _reindex_non_unique( @overload def join( self, - other, + other: Index, *, how: str_t = ..., level: Level = ..., @@ -4545,7 +4545,7 @@ def join( @overload def join( self, - other, + other: Index, *, how: str_t = ..., level: Level = ..., @@ -4557,7 +4557,7 @@ def join( @overload def join( self, - other, + other: Index, *, how: str_t = ..., level: Level = ..., @@ -4571,7 +4571,7 @@ def join( @_maybe_return_indexers def join( self, - other, + other: Index, how: str_t = "left", level: Level = None, return_indexers: bool = False, From 9ed63146759fa433787f6962c36f7499efe1a8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 2 Apr 2022 23:57:34 -0400 Subject: [PATCH 3/4] whatsnew --- doc/source/whatsnew/v1.5.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 0b8f11fc4749b..1e3edfa03f93e 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -427,6 +427,7 @@ Other Deprecations - Deprecated behavior of method :meth:`DataFrame.quantile`, attribute ``numeric_only`` will default False. Including datetime/timedelta columns in the result (:issue:`7308`). - Deprecated :attr:`Timedelta.freq` and :attr:`Timedelta.is_populated` (:issue:`46430`) - Deprecated :attr:`Timedelta.delta` (:issue:`46476`) +- Deprecated positional arguments to :meth:`ndex.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`) - .. --------------------------------------------------------------------------- From 47c17f2867d4d508ad5623ad2099c09f5f2bb6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 3 Apr 2022 00:14:13 -0400 Subject: [PATCH 4/4] typo --- doc/source/whatsnew/v1.5.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index d0b236df317ac..f9cd309bbc9a6 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -426,7 +426,7 @@ Other Deprecations - Deprecated behavior of method :meth:`DataFrame.quantile`, attribute ``numeric_only`` will default False. Including datetime/timedelta columns in the result (:issue:`7308`). - Deprecated :attr:`Timedelta.freq` and :attr:`Timedelta.is_populated` (:issue:`46430`) - Deprecated :attr:`Timedelta.delta` (:issue:`46476`) -- Deprecated positional arguments to :meth:`ndex.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`) +- Deprecated positional arguments to :meth:`Index.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`) - .. ---------------------------------------------------------------------------