Skip to content

Commit cf1aa9e

Browse files
authored
BUG: item_cache invalidation in get_numeric_data (#35882)
1 parent 8c3ad64 commit cf1aa9e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

doc/source/whatsnew/v1.1.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Bug fixes
3636
- Bug in :meth:`Float64Index.__contains__` incorrectly raising ``TypeError`` instead of returning ``False`` (:issue:`35788`)
3737
- Bug in :meth:`Series.dt.isocalendar` and :meth:`DatetimeIndex.isocalendar` that returned incorrect year for certain dates (:issue:`36032`)
3838
- Bug in :class:`DataFrame` indexing returning an incorrect :class:`Series` in some cases when the series has been altered and a cache not invalidated (:issue:`33675`)
39+
- Bug in :meth:`DataFrame.corr` causing subsequent indexing lookups to be incorrect (:issue:`35882`)
3940

4041
.. ---------------------------------------------------------------------------
4142

pandas/core/internals/managers.py

-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@ def get_numeric_data(self, copy: bool = False) -> "BlockManager":
691691
copy : bool, default False
692692
Whether to copy the blocks
693693
"""
694-
self._consolidate_inplace()
695694
return self._combine([b for b in self.blocks if b.is_numeric], copy)
696695

697696
def _combine(self: T, blocks: List[Block], copy: bool = True) -> T:

pandas/tests/frame/methods/test_cov_corr.py

+17
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,23 @@ def test_corr_nullable_integer(self, nullable_column, other_column, method):
191191
expected = pd.DataFrame(np.ones((2, 2)), columns=["a", "b"], index=["a", "b"])
192192
tm.assert_frame_equal(result, expected)
193193

194+
def test_corr_item_cache(self):
195+
# Check that corr does not lead to incorrect entries in item_cache
196+
197+
df = pd.DataFrame({"A": range(10)})
198+
df["B"] = range(10)[::-1]
199+
200+
ser = df["A"] # populate item_cache
201+
assert len(df._mgr.blocks) == 2
202+
203+
_ = df.corr()
204+
205+
# Check that the corr didnt break link between ser and df
206+
ser.values[0] = 99
207+
assert df.loc[0, "A"] == 99
208+
assert df["A"] is ser
209+
assert df.values[0, 0] == 99
210+
194211

195212
class TestDataFrameCorrWith:
196213
def test_corrwith(self, datetime_frame):

0 commit comments

Comments
 (0)