Skip to content

BUG: frame._item_cache not cleared when Series is altered #36051

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 30 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4c5eddd
REF: remove unnecesary try/except
jbrockmendel Aug 21, 2020
c632c9f
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Aug 21, 2020
9e64be3
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Aug 21, 2020
42649fb
TST: add test for agg on ordered categorical cols (#35630)
mathurk1 Aug 21, 2020
47121dd
TST: resample does not yield empty groups (#10603) (#35799)
tkmz-n Aug 21, 2020
1decb3e
revert accidental rebase
jbrockmendel Aug 22, 2020
57c5dd3
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 22, 2020
a358463
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 23, 2020
ffa7ad7
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 23, 2020
e5e98d4
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 24, 2020
408db5a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 24, 2020
d3493cf
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
75a805a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
9f61070
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
2d10f6e
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 26, 2020
3e20187
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 26, 2020
e27d07f
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 27, 2020
c52bed4
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 27, 2020
b69d4d7
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 28, 2020
1c5f8fd
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 28, 2020
061c9e2
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 28, 2020
0129a83
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 30, 2020
4d0d8e8
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 30, 2020
715848f
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 30, 2020
01f9c50
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 31, 2020
5f4f7dc
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 31, 2020
4f1f4e1
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 31, 2020
e97fc57
BUG: frame._item_cache not cleared when Series is altered
jbrockmendel Sep 1, 2020
bdb8580
Merge branch 'master' of https://github.com/pandas-dev/pandas into bu…
jbrockmendel Sep 1, 2020
9f0945c
whatsnew
jbrockmendel Sep 1, 2020
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Bug fixes
- Bug in :meth:`DataFrame.apply` with ``result_type="reduce"`` returning with incorrect index (:issue:`35683`)
- Bug in :meth:`DateTimeIndex.format` and :meth:`PeriodIndex.format` with ``name=True`` setting the first item to ``"None"`` where it should bw ``""`` (:issue:`35712`)
- Bug in :meth:`Float64Index.__contains__` incorrectly raising ``TypeError`` instead of returning ``False`` (:issue:`35788`)
- 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:`36051`)

.. ---------------------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3315,6 +3315,10 @@ def _maybe_update_cacher(
if len(self) == len(ref):
# otherwise, either self or ref has swapped in new arrays
ref._maybe_cache_changed(cacher[0], self)
else:
# GH#33675 we have swapped in a new array, so parent
# reference to self is now invalid
ref._item_cache.pop(cacher[0], None)

if verify_is_copy:
self._check_setitem_copy(stacklevel=5, t="referant")
Expand Down
15 changes: 11 additions & 4 deletions pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,20 @@ def test_drop_and_dropna_caching(self):
df2 = df.copy()
df["A"].dropna()
tm.assert_series_equal(df["A"], original)
return_value = df["A"].dropna(inplace=True)
tm.assert_series_equal(df["A"], expected)

ser = df["A"]
return_value = ser.dropna(inplace=True)
tm.assert_series_equal(ser, expected)
tm.assert_series_equal(df["A"], original)
assert return_value is None

df2["A"].drop([1])
tm.assert_series_equal(df2["A"], original)
return_value = df2["A"].drop([1], inplace=True)
tm.assert_series_equal(df2["A"], original.drop([1]))

ser = df2["A"]
return_value = ser.drop([1], inplace=True)
tm.assert_series_equal(ser, original.drop([1]))
tm.assert_series_equal(df2["A"], original)
assert return_value is None

def test_dropna_corner(self, float_frame):
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/indexing/test_chaining_and_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ def test_setitem_cache_updating(self):
tm.assert_frame_equal(out, expected)
tm.assert_series_equal(out["A"], expected["A"])

def test_altering_series_clears_parent_cache(self):
# GH #33675
df = pd.DataFrame([[1, 2], [3, 4]], index=["a", "b"], columns=["A", "B"])
ser = df["A"]

assert "A" in df._item_cache

# Adding a new entry to ser swaps in a new array, so "A" needs to
# be removed from df._item_cache
ser["c"] = 5
assert len(ser) == 3
assert "A" not in df._item_cache
assert df["A"] is not ser
assert len(df["A"]) == 2


class TestChaining:
def test_setitem_chained_setfault(self):
Expand Down