diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 38c495e1dd0f3..0c98a779424bd 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -168,10 +168,6 @@ def _holder(self): def _consolidate_key(self): return (self._can_consolidate, self.dtype.name) - @property - def _is_single_block(self) -> bool: - return self.ndim == 1 - @property def is_view(self) -> bool: """ return a boolean if I am possibly a view """ @@ -259,7 +255,7 @@ def make_block_same_class(self, values, placement=None, ndim=None): def __repr__(self) -> str: # don't want to print out all of the items here name = type(self).__name__ - if self._is_single_block: + if self.ndim == 1: result = f"{name}: {len(self)} dtype: {self.dtype}" else: @@ -476,8 +472,7 @@ def downcast(self, dtypes=None): values = self.values - # single block handling - if self._is_single_block: + if self.ndim == 1: # try to cast all non-floats here if dtypes is None: diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index eaf59051205d6..6055a6205d286 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -220,16 +220,8 @@ def set_axis(self, axis: int, new_labels: Index) -> None: @property def _is_single_block(self) -> bool: - if self.ndim == 1: - return True - - if len(self.blocks) != 1: - return False - - blk = self.blocks[0] - return blk.mgr_locs.is_slice_like and blk.mgr_locs.as_slice == slice( - 0, len(self), 1 - ) + # Assumes we are 2D; overriden by SingleBlockManager + return len(self.blocks) == 1 def _rebuild_blknos_and_blklocs(self) -> None: """ @@ -1486,6 +1478,7 @@ class SingleBlockManager(BlockManager): _is_consolidated = True _known_consolidated = True __slots__ = () + _is_single_block = True def __init__( self,