Skip to content

REF: SingleBlockManager dont subclass BlockManager #40625

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 10 commits into from
Apr 8, 2021
2 changes: 1 addition & 1 deletion pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@
]

# internals
Manager = Union["ArrayManager", "BlockManager"]
Manager = Union["ArrayManager", "BlockManager", "SingleBlockManager"]
SingleManager = Union["SingleArrayManager", "SingleBlockManager"]
20 changes: 20 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ class DataFrame(NDFrame, OpsMixin):
_HANDLED_TYPES = (Series, Index, ExtensionArray, np.ndarray)
_accessors: set[str] = {"sparse"}
_hidden_attrs: frozenset[str] = NDFrame._hidden_attrs | frozenset([])
_mgr: BlockManager | ArrayManager

@property
def _constructor(self) -> type[DataFrame]:
Expand Down Expand Up @@ -3518,6 +3519,25 @@ def _get_value(self, index, col, takeable: bool = False) -> Scalar:
index = self.index.get_loc(index)
return self._get_value(index, col, takeable=True)

def _get_item_cache(self, item):
"""Return the cached item, item represents a label indexer."""
cache = self._item_cache
res = cache.get(item)
if res is None:
# All places that call _get_item_cache have unique columns,
# pending resolution of GH#33047

loc = self.columns.get_loc(item)
values = self._mgr.iget(loc)
res = self._box_col_values(values, loc).__finalize__(self)

cache[item] = res
res._set_as_cached(item, self)

# for a chain
res._is_copy = self._is_copy
return res

def __setitem__(self, key, value):
key = com.apply_if_callable(key, self)

Expand Down
20 changes: 0 additions & 20 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3886,26 +3886,6 @@ class animal locomotion
def __getitem__(self, item):
raise AbstractMethodError(self)

@final
def _get_item_cache(self, item):
"""Return the cached item, item represents a label indexer."""
cache = self._item_cache
res = cache.get(item)
if res is None:
# All places that call _get_item_cache have unique columns,
# pending resolution of GH#33047

loc = self.columns.get_loc(item)
values = self._mgr.iget(loc)
res = self._box_col_values(values, loc).__finalize__(self)

cache[item] = res
res._set_as_cached(item, self)

# for a chain
res._is_copy = self._is_copy
return res

def _slice(self: FrameOrSeries, slobj: slice, axis=0) -> FrameOrSeries:
"""
Construct a slice of this container.
Expand Down
Loading