Skip to content

Commit dbe5927

Browse files
authored
TYP: Adjust typing for Blockplacement.__getitem__ (#51036)
* TYP: Adjust typing for Blockplacement.__getitem__ * Fix typing * Fix typing
1 parent 961314d commit dbe5927

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

pandas/_libs/internals.pyi

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class BlockPlacement:
4444
@property
4545
def is_slice_like(self) -> bool: ...
4646
@overload
47-
def __getitem__(self, loc: slice | Sequence[int]) -> BlockPlacement: ...
47+
def __getitem__(
48+
self, loc: slice | Sequence[int] | npt.NDArray[np.intp]
49+
) -> BlockPlacement: ...
4850
@overload
4951
def __getitem__(self, loc: int) -> int: ...
5052
def __iter__(self) -> Iterator[int]: ...

pandas/core/internals/blocks.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ def getitem_block(self, slicer: slice | npt.NDArray[np.intp]) -> Block:
258258
# is from internals.concat, and we can verify that never happens
259259
# with 1-column blocks, i.e. never for ExtensionBlock.
260260

261-
# Invalid index type "Union[slice, ndarray[Any, dtype[signedinteger[Any]]]]"
262-
# for "BlockPlacement"; expected type "Union[slice, Sequence[int]]"
263-
new_mgr_locs = self._mgr_locs[slicer] # type: ignore[index]
261+
new_mgr_locs = self._mgr_locs[slicer]
264262

265263
new_values = self._slice(slicer)
266264

pandas/core/internals/managers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1320,11 +1320,11 @@ def _iset_split_block(
13201320

13211321
nbs_tup = tuple(blk.delete(blk_locs))
13221322
if value is not None:
1323-
# error: No overload variant of "__getitem__" of "BlockPlacement" matches
1324-
# argument type "ndarray[Any, Any]" [call-overload]
1323+
# Argument 1 to "BlockPlacement" has incompatible type "BlockPlacement";
1324+
# expected "Union[int, slice, ndarray[Any, Any]]"
13251325
first_nb = new_block_2d(
13261326
value,
1327-
BlockPlacement(blk.mgr_locs[blk_locs]), # type: ignore[call-overload]
1327+
BlockPlacement(blk.mgr_locs[blk_locs]), # type: ignore[arg-type]
13281328
)
13291329
else:
13301330
first_nb = nbs_tup[0]

0 commit comments

Comments
 (0)