@@ -307,7 +307,9 @@ def __repr__(self) -> str:
307307 def __len__ (self ) -> int :
308308 return len (self .values )
309309
310- def _slice (self , slicer ) -> ArrayLike :
310+ def _slice (
311+ self , slicer : slice | npt .NDArray [np .bool_ ] | npt .NDArray [np .intp ]
312+ ) -> ArrayLike :
311313 """return a slice of my values"""
312314
313315 return self .values [slicer ]
@@ -319,8 +321,13 @@ def getitem_block(self, slicer: slice | npt.NDArray[np.intp]) -> Block:
319321
320322 Only supports slices that preserve dimensionality.
321323 """
322- axis0_slicer = slicer [0 ] if isinstance (slicer , tuple ) else slicer
323- new_mgr_locs = self ._mgr_locs [axis0_slicer ]
324+ # Note: the only place where we are called with ndarray[intp]
325+ # is from internals.concat, and we can verify that never happens
326+ # with 1-column blocks, i.e. never for ExtensionBlock.
327+
328+ # Invalid index type "Union[slice, ndarray[Any, dtype[signedinteger[Any]]]]"
329+ # for "BlockPlacement"; expected type "Union[slice, Sequence[int]]"
330+ new_mgr_locs = self ._mgr_locs [slicer ] # type: ignore[index]
324331
325332 new_values = self ._slice (slicer )
326333
@@ -1626,43 +1633,43 @@ def take_nd(
16261633
16271634 return self .make_block_same_class (new_values , new_mgr_locs )
16281635
1629- def _slice (self , slicer ) -> ExtensionArray :
1636+ def _slice (
1637+ self , slicer : slice | npt .NDArray [np .bool_ ] | npt .NDArray [np .intp ]
1638+ ) -> ExtensionArray :
16301639 """
16311640 Return a slice of my values.
16321641
16331642 Parameters
16341643 ----------
1635- slicer : slice, ndarray[int], or a tuple of these
1644+ slicer : slice, ndarray[int], or ndarray[bool]
16361645 Valid (non-reducing) indexer for self.values.
16371646
16381647 Returns
16391648 -------
16401649 ExtensionArray
16411650 """
1651+ # Notes: ndarray[bool] is only reachable when via getitem_mgr, which
1652+ # is only for Series, i.e. self.ndim == 1.
1653+
16421654 # return same dims as we currently have
1643- if not isinstance ( slicer , tuple ) and self .ndim == 2 :
1655+ if self .ndim == 2 :
16441656 # reached via getitem_block via _slice_take_blocks_ax0
16451657 # TODO(EA2D): won't be necessary with 2D EAs
1646- slicer = (slicer , slice (None ))
16471658
1648- if isinstance (slicer , tuple ) and len (slicer ) == 2 :
1649- first = slicer [0 ]
1650- if not isinstance (first , slice ):
1659+ if not isinstance (slicer , slice ):
16511660 raise AssertionError (
1652- "invalid slicing for a 1-ndim ExtensionArray" , first
1661+ "invalid slicing for a 1-ndim ExtensionArray" , slicer
16531662 )
16541663 # GH#32959 only full-slicers along fake-dim0 are valid
16551664 # TODO(EA2D): won't be necessary with 2D EAs
16561665 # range(1) instead of self._mgr_locs to avoid exception on [::-1]
16571666 # see test_iloc_getitem_slice_negative_step_ea_block
1658- new_locs = range (1 )[first ]
1659- if len (new_locs ):
1660- # effectively slice(None)
1661- slicer = slicer [1 ]
1662- else :
1667+ new_locs = range (1 )[slicer ]
1668+ if not len (new_locs ):
16631669 raise AssertionError (
16641670 "invalid slicing for a 1-ndim ExtensionArray" , slicer
16651671 )
1672+ slicer = slice (None )
16661673
16671674 return self .values [slicer ]
16681675
0 commit comments