From d72eeb32b4b6fb9cb5ecb4f3f322a8f29e24be18 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 27 Jan 2023 20:28:43 -0500 Subject: [PATCH 1/3] TYP: Adjust typing for Blockplacement.__getitem__ --- pandas/_libs/internals.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/internals.pyi b/pandas/_libs/internals.pyi index 143f6b68deaa6..9ddb33515b254 100644 --- a/pandas/_libs/internals.pyi +++ b/pandas/_libs/internals.pyi @@ -44,7 +44,9 @@ class BlockPlacement: @property def is_slice_like(self) -> bool: ... @overload - def __getitem__(self, loc: slice | Sequence[int]) -> BlockPlacement: ... + def __getitem__( + self, loc: slice | Sequence[int] | np.ndarray + ) -> BlockPlacement: ... @overload def __getitem__(self, loc: int) -> int: ... def __iter__(self) -> Iterator[int]: ... From b3bccf1582f2d4af44602617d5b7371e6898392f Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 27 Jan 2023 22:14:47 -0500 Subject: [PATCH 2/3] Fix typing --- pandas/core/internals/blocks.py | 4 +--- pandas/core/internals/managers.py | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 8fb6a18ca137a..b7da5d82c85f3 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -258,9 +258,7 @@ def getitem_block(self, slicer: slice | npt.NDArray[np.intp]) -> Block: # is from internals.concat, and we can verify that never happens # with 1-column blocks, i.e. never for ExtensionBlock. - # Invalid index type "Union[slice, ndarray[Any, dtype[signedinteger[Any]]]]" - # for "BlockPlacement"; expected type "Union[slice, Sequence[int]]" - new_mgr_locs = self._mgr_locs[slicer] # type: ignore[index] + new_mgr_locs = self._mgr_locs[slicer] new_values = self._slice(slicer) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 71d8b20f18457..81c5810d29456 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1320,11 +1320,11 @@ def _iset_split_block( nbs_tup = tuple(blk.delete(blk_locs)) if value is not None: - # error: No overload variant of "__getitem__" of "BlockPlacement" matches - # argument type "ndarray[Any, Any]" [call-overload] + # Argument 1 to "BlockPlacement" has incompatible type "BlockPlacement"; + # expected "Union[int, slice, ndarray[Any, Any]]" first_nb = new_block_2d( value, - BlockPlacement(blk.mgr_locs[blk_locs]), # type: ignore[call-overload] + BlockPlacement(blk.mgr_locs[blk_locs]), # type: ignore[arg-type] ) else: first_nb = nbs_tup[0] From 832cad3053134b5463f00aedcf59aafcdcde6ca7 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Mon, 30 Jan 2023 21:00:08 +0100 Subject: [PATCH 3/3] Fix typing --- pandas/_libs/internals.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/internals.pyi b/pandas/_libs/internals.pyi index 9ddb33515b254..79bdbea71e4d8 100644 --- a/pandas/_libs/internals.pyi +++ b/pandas/_libs/internals.pyi @@ -45,7 +45,7 @@ class BlockPlacement: def is_slice_like(self) -> bool: ... @overload def __getitem__( - self, loc: slice | Sequence[int] | np.ndarray + self, loc: slice | Sequence[int] | npt.NDArray[np.intp] ) -> BlockPlacement: ... @overload def __getitem__(self, loc: int) -> int: ...