Skip to content

REF: avoid access to _mgr.blocks -> _mgr._is_single_block #37155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5474,7 +5474,7 @@ def _consolidate(self):

@property
def _is_mixed_type(self) -> bool_t:
if len(self._mgr.blocks) == 1:
if self._mgr.is_single_block:
return False

if self._mgr.any_extension_types:
Expand Down Expand Up @@ -6262,7 +6262,7 @@ def fillna(
axis = self._get_axis_number(axis)

if value is None:
if len(self._mgr.blocks) > 1 and axis == 1:
if not self._mgr.is_single_block and axis == 1:
if inplace:
raise NotImplementedError()
result = self.T.fillna(method=method, limit=limit).T
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ def _setitem_with_indexer(self, indexer, value):
info_axis = self.obj._info_axis_number

# maybe partial set
take_split_path = len(self.obj._mgr.blocks) > 1
take_split_path = not self.obj._mgr.is_single_block

# if there is only one block/type, still have to take split path
# unless the block is one-dimensional or it can hold the value
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _get_mgr_concatenation_plan(mgr, indexers):
blklocs = algos.take_1d(mgr.blklocs, ax0_indexer, fill_value=-1)
else:

if mgr._is_single_block:
if mgr.is_single_block:
blk = mgr.blocks[0]
return [(blk.mgr_locs, JoinUnit(blk, mgr_shape, indexers))]

Expand Down
8 changes: 4 additions & 4 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def set_axis(self, axis: int, new_labels: Index) -> None:
self.axes[axis] = new_labels

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

Expand Down Expand Up @@ -833,7 +833,7 @@ def as_array(
# mutating the original object
copy = copy or na_value is not lib.no_default

if self._is_single_block:
if self.is_single_block:
blk = self.blocks[0]
if blk.is_extension:
# Avoid implicit conversion of extension blocks to object
Expand Down Expand Up @@ -1313,7 +1313,7 @@ def _slice_take_blocks_ax0(
slice_or_indexer, self.shape[0], allow_fill=allow_fill
)

if self._is_single_block:
if self.is_single_block:
blk = self.blocks[0]

if sl_type in ("slice", "mask"):
Expand Down Expand Up @@ -1503,7 +1503,7 @@ class SingleBlockManager(BlockManager):
_is_consolidated = True
_known_consolidated = True
__slots__ = ()
_is_single_block = True
is_single_block = True

def __init__(
self,
Expand Down