Skip to content

Commit 3e8f14f

Browse files
authored
REF: simplify _is_single_block/is_mixed_type (#34935)
1 parent d000e70 commit 3e8f14f

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

pandas/core/internals/blocks.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ def _holder(self):
168168
def _consolidate_key(self):
169169
return (self._can_consolidate, self.dtype.name)
170170

171-
@property
172-
def _is_single_block(self) -> bool:
173-
return self.ndim == 1
174-
175171
@property
176172
def is_view(self) -> bool:
177173
""" return a boolean if I am possibly a view """
@@ -259,7 +255,7 @@ def make_block_same_class(self, values, placement=None, ndim=None):
259255
def __repr__(self) -> str:
260256
# don't want to print out all of the items here
261257
name = type(self).__name__
262-
if self._is_single_block:
258+
if self.ndim == 1:
263259
result = f"{name}: {len(self)} dtype: {self.dtype}"
264260
else:
265261

@@ -476,8 +472,7 @@ def downcast(self, dtypes=None):
476472

477473
values = self.values
478474

479-
# single block handling
480-
if self._is_single_block:
475+
if self.ndim == 1:
481476

482477
# try to cast all non-floats here
483478
if dtypes is None:

pandas/core/internals/managers.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,8 @@ def set_axis(self, axis: int, new_labels: Index) -> None:
220220

221221
@property
222222
def _is_single_block(self) -> bool:
223-
if self.ndim == 1:
224-
return True
225-
226-
if len(self.blocks) != 1:
227-
return False
228-
229-
blk = self.blocks[0]
230-
return blk.mgr_locs.is_slice_like and blk.mgr_locs.as_slice == slice(
231-
0, len(self), 1
232-
)
223+
# Assumes we are 2D; overriden by SingleBlockManager
224+
return len(self.blocks) == 1
233225

234226
def _rebuild_blknos_and_blklocs(self) -> None:
235227
"""
@@ -1486,6 +1478,7 @@ class SingleBlockManager(BlockManager):
14861478
_is_consolidated = True
14871479
_known_consolidated = True
14881480
__slots__ = ()
1481+
_is_single_block = True
14891482

14901483
def __init__(
14911484
self,

0 commit comments

Comments
 (0)