From c8525051c73b33e670b4427f6014d2381047f573 Mon Sep 17 00:00:00 2001 From: Soumik Dutta Date: Mon, 3 Oct 2022 00:33:02 +0530 Subject: [PATCH 1/6] fixed warning unexpected-keyword-arg Signed-off-by: Soumik Dutta --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 47e3314c6d9c3..c0cfe6453a70d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -738,7 +738,7 @@ def _with_infer(cls, *args, **kwargs): return result @cache_readonly - def _constructor(self: _IndexT) -> type[_IndexT]: + def _constructor(self: _IndexT, name: Hashable, dtype, copy: bool) -> type[_IndexT]: return type(self) @final From 338962adce4bf5aa557f11153b45a2fc5f9f04d4 Mon Sep 17 00:00:00 2001 From: Soumik Dutta Date: Mon, 3 Oct 2022 00:49:12 +0530 Subject: [PATCH 2/6] make copy and dtype optional Signed-off-by: Soumik Dutta --- pandas/core/indexes/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index c0cfe6453a70d..7300822bbb0ba 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -14,6 +14,7 @@ Iterable, Literal, NoReturn, + Optional, Sequence, TypeVar, cast, @@ -738,7 +739,12 @@ def _with_infer(cls, *args, **kwargs): return result @cache_readonly - def _constructor(self: _IndexT, name: Hashable, dtype, copy: bool) -> type[_IndexT]: + def _constructor( + self: _IndexT, + name: Hashable, + copy: Optional(bool), + dtype=None, + ) -> type[_IndexT]: return type(self) @final From 3ebcf2eddb674ae6f2c01fb77a7ed18aa91eecff Mon Sep 17 00:00:00 2001 From: Soumik Dutta Date: Mon, 3 Oct 2022 00:52:29 +0530 Subject: [PATCH 3/6] make copy and dtype optional Signed-off-by: Soumik Dutta --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 7300822bbb0ba..36f6e2b1d0b6a 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -742,7 +742,7 @@ def _with_infer(cls, *args, **kwargs): def _constructor( self: _IndexT, name: Hashable, - copy: Optional(bool), + copy: Optional[bool] = None, dtype=None, ) -> type[_IndexT]: return type(self) From c44e4a7687036d347f381731f3d89b919b540f64 Mon Sep 17 00:00:00 2001 From: Soumik Dutta Date: Mon, 3 Oct 2022 01:03:05 +0530 Subject: [PATCH 4/6] make name optional Signed-off-by: Soumik Dutta --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 36f6e2b1d0b6a..71dd1f1e496d6 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -741,7 +741,7 @@ def _with_infer(cls, *args, **kwargs): @cache_readonly def _constructor( self: _IndexT, - name: Hashable, + name: Optional[Hashable] = None, copy: Optional[bool] = None, dtype=None, ) -> type[_IndexT]: From bf2191011ca149a57817e122323fcdc009fb208f Mon Sep 17 00:00:00 2001 From: Soumik Dutta Date: Mon, 3 Oct 2022 01:37:46 +0530 Subject: [PATCH 5/6] update to newer syntax of optional types Signed-off-by: Soumik Dutta --- pandas/core/indexes/base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 71dd1f1e496d6..7a8e030b2d536 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -14,7 +14,6 @@ Iterable, Literal, NoReturn, - Optional, Sequence, TypeVar, cast, @@ -741,8 +740,8 @@ def _with_infer(cls, *args, **kwargs): @cache_readonly def _constructor( self: _IndexT, - name: Optional[Hashable] = None, - copy: Optional[bool] = None, + name: Hashable | None = None, + copy: bool | None = None, dtype=None, ) -> type[_IndexT]: return type(self) From ab0b16c8ce0cd45cbdd72cde4e849125e4f3f747 Mon Sep 17 00:00:00 2001 From: Soumik Dutta Date: Wed, 5 Oct 2022 11:46:08 +0530 Subject: [PATCH 6/6] add keyword arguments to constructors of MultiIndex and RangeIndex Signed-off-by: Soumik Dutta --- pandas/core/indexes/multi.py | 7 ++++++- pandas/core/indexes/range.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 574dfdf48055d..66c3d15676c5a 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1148,7 +1148,12 @@ def _engine(self): # Return type "Callable[..., MultiIndex]" of "_constructor" incompatible with return # type "Type[MultiIndex]" in supertype "Index" @property - def _constructor(self) -> Callable[..., MultiIndex]: # type: ignore[override] + def _constructor( + self: MultiIndex, + name: Hashable | None = None, + copy: bool | None = None, + dtype=None, + ) -> Callable[..., MultiIndex]: # type: ignore[override] return type(self).from_tuples @doc(Index._shallow_copy) diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index 0948c5a3825d0..41ab0125c5014 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -188,7 +188,12 @@ def _simple_new(cls, values: range, name: Hashable = None) -> RangeIndex: # error: Return type "Type[Int64Index]" of "_constructor" incompatible with return # type "Type[RangeIndex]" in supertype "Index" @cache_readonly - def _constructor(self) -> type[Int64Index]: # type: ignore[override] + def _constructor( + self: RangeIndex, + name: Hashable | None = None, + copy: bool | None = None, + dtype=None + ) -> type[Int64Index]: # type: ignore[override] """return the class to use for construction""" return Int64Index