Skip to content

CLN: helper attribute to check for ArrayManager #44676

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

Closed
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/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ def _is_homogeneous_type(self) -> bool:
... "B": np.array([1, 2], dtype=np.int64)})._is_homogeneous_type
False
"""
if isinstance(self._mgr, ArrayManager):
if self._using_array_manager:
return len({arr.dtype for arr in self._mgr.arrays}) == 1
if self._mgr.any_extension_types:
return len({block.dtype for block in self._mgr.blocks}) == 1
Expand All @@ -878,7 +878,7 @@ def _can_fast_transpose(self) -> bool:
"""
Can we transpose this DataFrame without creating any new array objects.
"""
if isinstance(self._mgr, ArrayManager):
if self._using_array_manager:
return False
blocks = self._mgr.blocks
if len(blocks) != 1:
Expand Down
10 changes: 9 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ def _as_manager(self: NDFrameT, typ: str, copy: bool_t = True) -> NDFrameT:
# fastpath of passing a manager doesn't check the option/manager class
return self._constructor(new_mgr).__finalize__(self)

@property
def _using_array_manager(self) -> bool_t:
"""
Private attribute to quickly check if the DataFrame/Series is
backed by an ArrayManager or not.
"""
return isinstance(self._mgr, (ArrayManager, SingleArrayManager))

# ----------------------------------------------------------------------
# attrs and flags

Expand Down Expand Up @@ -5606,7 +5614,7 @@ def _protect_consolidate(self, f):
Consolidate _mgr -- if the blocks have changed, then clear the
cache
"""
if isinstance(self._mgr, (ArrayManager, SingleArrayManager)):
if self._using_array_manager:
return f()
blocks_before = len(self._mgr.blocks)
result = f()
Expand Down
6 changes: 1 addition & 5 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,11 +1552,7 @@ def _setitem_with_indexer(self, indexer, value, name="iloc"):

# 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
if (
not take_split_path
and getattr(self.obj._mgr, "blocks", False)
and self.ndim > 1
):
if not take_split_path and not self.obj._using_array_manager and self.ndim > 1:
# in case of dict, keys are indices
val = list(value.values()) if isinstance(value, dict) else value
blk = self.obj._mgr.blocks[0]
Expand Down