diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 010358d3a21ec..d0d67a01584c9 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -881,8 +881,13 @@ def take_nd( ) # Called from three places in managers, all of which satisfy - # this assertion + # these assertions + if isinstance(self, ExtensionBlock): + # NB: in this case, the 'axis' kwarg will be ignored in the + # algos.take_nd call above. + assert not (self.ndim == 1 and new_mgr_locs is None) assert not (axis == 0 and new_mgr_locs is None) + if new_mgr_locs is None: new_mgr_locs = self._mgr_locs @@ -1752,33 +1757,6 @@ def is_view(self) -> bool: def is_numeric(self): return self.values.dtype._is_numeric - def take_nd( - self, - indexer: npt.NDArray[np.intp], - axis: int = 0, - new_mgr_locs: BlockPlacement | None = None, - fill_value=lib.no_default, - ) -> Block: - """ - Take values according to indexer and return them as a block. - """ - if fill_value is lib.no_default: - fill_value = None - - # TODO(EA2D): special case not needed with 2D EAs - # axis doesn't matter; we are really a single-dim object - # but are passed the axis depending on the calling routing - # if its REALLY axis 0, then this will be a reindex and not a take - new_values = self.values.take(indexer, fill_value=fill_value, allow_fill=True) - - # Called from three places in managers, all of which satisfy - # this assertion - assert not (self.ndim == 1 and new_mgr_locs is None) - if new_mgr_locs is None: - new_mgr_locs = self._mgr_locs - - return self.make_block_same_class(new_values, new_mgr_locs) - def _slice( self, slicer: slice | npt.NDArray[np.bool_] | npt.NDArray[np.intp] ) -> ExtensionArray: diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 9f4c799941afd..fe5748b240eab 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -725,6 +725,9 @@ def reindex_indexer( result.axes[axis] = new_axis return result + # Should be intp, but in some cases we get int64 on 32bit builds + assert isinstance(indexer, np.ndarray) + # some axes don't allow reindexing with dups if not allow_dups: self.axes[axis]._validate_can_reindex(indexer)