Skip to content

Commit 5a4cfdc

Browse files
jorisvandenbosscheKevin D Smith
authored and
Kevin D Smith
committed
REF: avoid access to _mgr.blocks -> _mgr._is_single_block (pandas-dev#37155)
1 parent f572a95 commit 5a4cfdc

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5474,7 +5474,7 @@ def _consolidate(self):
54745474

54755475
@property
54765476
def _is_mixed_type(self) -> bool_t:
5477-
if len(self._mgr.blocks) == 1:
5477+
if self._mgr.is_single_block:
54785478
return False
54795479

54805480
if self._mgr.any_extension_types:
@@ -6262,7 +6262,7 @@ def fillna(
62626262
axis = self._get_axis_number(axis)
62636263

62646264
if value is None:
6265-
if len(self._mgr.blocks) > 1 and axis == 1:
6265+
if not self._mgr.is_single_block and axis == 1:
62666266
if inplace:
62676267
raise NotImplementedError()
62686268
result = self.T.fillna(method=method, limit=limit).T

pandas/core/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ def _setitem_with_indexer(self, indexer, value):
15401540
info_axis = self.obj._info_axis_number
15411541

15421542
# maybe partial set
1543-
take_split_path = len(self.obj._mgr.blocks) > 1
1543+
take_split_path = not self.obj._mgr.is_single_block
15441544

15451545
# if there is only one block/type, still have to take split path
15461546
# unless the block is one-dimensional or it can hold the value

pandas/core/internals/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _get_mgr_concatenation_plan(mgr, indexers):
115115
blklocs = algos.take_1d(mgr.blklocs, ax0_indexer, fill_value=-1)
116116
else:
117117

118-
if mgr._is_single_block:
118+
if mgr.is_single_block:
119119
blk = mgr.blocks[0]
120120
return [(blk.mgr_locs, JoinUnit(blk, mgr_shape, indexers))]
121121

pandas/core/internals/managers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def set_axis(self, axis: int, new_labels: Index) -> None:
225225
self.axes[axis] = new_labels
226226

227227
@property
228-
def _is_single_block(self) -> bool:
228+
def is_single_block(self) -> bool:
229229
# Assumes we are 2D; overridden by SingleBlockManager
230230
return len(self.blocks) == 1
231231

@@ -833,7 +833,7 @@ def as_array(
833833
# mutating the original object
834834
copy = copy or na_value is not lib.no_default
835835

836-
if self._is_single_block:
836+
if self.is_single_block:
837837
blk = self.blocks[0]
838838
if blk.is_extension:
839839
# Avoid implicit conversion of extension blocks to object
@@ -1313,7 +1313,7 @@ def _slice_take_blocks_ax0(
13131313
slice_or_indexer, self.shape[0], allow_fill=allow_fill
13141314
)
13151315

1316-
if self._is_single_block:
1316+
if self.is_single_block:
13171317
blk = self.blocks[0]
13181318

13191319
if sl_type in ("slice", "mask"):
@@ -1503,7 +1503,7 @@ class SingleBlockManager(BlockManager):
15031503
_is_consolidated = True
15041504
_known_consolidated = True
15051505
__slots__ = ()
1506-
_is_single_block = True
1506+
is_single_block = True
15071507

15081508
def __init__(
15091509
self,

0 commit comments

Comments
 (0)