Skip to content

Commit

Permalink
Backport PR #35882: BUG: item_cache invalidation in get_numeric_data (#…
Browse files Browse the repository at this point in the history
…36188)

Co-authored-by: jbrockmendel <jbrockmendel@gmail.com>
  • Loading branch information
meeseeksmachine and jbrockmendel committed Sep 7, 2020
1 parent d0a39d1 commit a715964
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.2.rst
Expand Up @@ -40,6 +40,7 @@ Bug fixes
- Bug in :class:`Series` constructor incorrectly raising a ``TypeError`` when passed an ordered set (:issue:`36044`)
- Bug in :meth:`Series.dt.isocalendar` and :meth:`DatetimeIndex.isocalendar` that returned incorrect year for certain dates (:issue:`36032`)
- 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`)
- Bug in :meth:`DataFrame.corr` causing subsequent indexing lookups to be incorrect (:issue:`35882`)

.. ---------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion pandas/core/internals/managers.py
Expand Up @@ -732,7 +732,6 @@ def get_numeric_data(self, copy: bool = False) -> "BlockManager":
copy : bool, default False
Whether to copy the blocks
"""
self._consolidate_inplace()
return self._combine([b for b in self.blocks if b.is_numeric], copy)

def _combine(self, blocks: List[Block], copy: bool = True) -> "BlockManager":
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/frame/methods/test_cov_corr.py
Expand Up @@ -191,6 +191,23 @@ def test_corr_nullable_integer(self, nullable_column, other_column, method):
expected = pd.DataFrame(np.ones((2, 2)), columns=["a", "b"], index=["a", "b"])
tm.assert_frame_equal(result, expected)

def test_corr_item_cache(self):
# Check that corr does not lead to incorrect entries in item_cache

df = pd.DataFrame({"A": range(10)})
df["B"] = range(10)[::-1]

ser = df["A"] # populate item_cache
assert len(df._mgr.blocks) == 2

_ = df.corr()

# Check that the corr didnt break link between ser and df
ser.values[0] = 99
assert df.loc[0, "A"] == 99
assert df["A"] is ser
assert df.values[0, 0] == 99


class TestDataFrameCorrWith:
def test_corrwith(self, datetime_frame):
Expand Down

0 comments on commit a715964

Please sign in to comment.