Skip to content

Commit 0875770

Browse files
committed
CLN: have _consolidate_inplace invalidate the cache when needed
1 parent 856c364 commit 0875770

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

pandas/core/frame.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -2100,15 +2100,10 @@ def _slice(self, slobj, axis=0, raise_on_error=False):
21002100
else:
21012101
mgr_axis = 0
21022102

2103-
# Super bad smell, need to review all this cache inval / block business
2104-
blocks_before = len(self._data.blocks)
2103+
self._consolidate_inplace()
21052104
new_data = self._data.get_slice(slobj, axis=mgr_axis,
21062105
raise_on_error=raise_on_error)
21072106

2108-
# Internal consolidation requires cache invalidation
2109-
if len(self._data.blocks) != blocks_before:
2110-
self._clear_item_cache()
2111-
21122107
return self._constructor(new_data)
21132108

21142109
def _box_item_values(self, key, values):

pandas/core/generic.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ def _expand_axes(self, key):
747747
# Consolidation of internals
748748

749749
def _consolidate_inplace(self):
750-
self._clear_item_cache()
751-
self._data = self._data.consolidate()
750+
f = lambda: self._data.consolidate()
751+
self._data = self._protect_consolidate(f)
752752

753753
def consolidate(self, inplace=False):
754754
"""
@@ -768,7 +768,8 @@ def consolidate(self, inplace=False):
768768
if inplace:
769769
self._consolidate_inplace()
770770
else:
771-
cons_data = self._data.consolidate()
771+
f = lambda: self._data.consolidate()
772+
cons_data = self._protect_consolidate(f)
772773
if cons_data is self._data:
773774
cons_data = cons_data.copy()
774775
return self._constructor(cons_data)

0 commit comments

Comments
 (0)