Skip to content

API / CoW: always return new objects for column access (don't use item_cache) #49450

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
also avoid populating the reverse cacher (pointing to DataFrame that …
…is parent of Series
  • Loading branch information
jorisvandenbossche committed Nov 1, 2022
commit 32fa0a42bde7a94b93adbe14b8620433daef90f2
5 changes: 5 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3752,6 +3752,11 @@ def _maybe_update_cacher(
verify_is_copy : bool, default True
Provide is_copy checks.
"""
if (
config.get_option("mode.copy_on_write")
and config.get_option("mode.data_manager") == "block"
):
return

if verify_is_copy:
self._check_setitem_copy(t="referent")
Expand Down
23 changes: 13 additions & 10 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,11 @@ def _set_as_cached(self, item, cacher) -> None:
Set the _cacher attribute on the calling object with a weakref to
cacher.
"""
if (
get_option("mode.copy_on_write")
and get_option("mode.data_manager") == "block"
):
return
self._cacher = (item, weakref.ref(cacher))

def _clear_item_cache(self) -> None:
Expand All @@ -1260,6 +1265,13 @@ def _maybe_update_cacher(
"""
See NDFrame._maybe_update_cacher.__doc__
"""
# for CoW, we never want to update the parent DataFrame cache
# if the Series changed, but don't keep track of any cacher
if (
get_option("mode.copy_on_write")
and get_option("mode.data_manager") == "block"
):
return
cacher = getattr(self, "_cacher", None)
if cacher is not None:
assert self.ndim == 1
Expand All @@ -1269,16 +1281,7 @@ def _maybe_update_cacher(
# a copy
if ref is None:
del self._cacher
# for CoW, we never want to update the parent DataFrame cache
# if the Series changed, and always pop the cached item
elif (
not (
get_option("mode.copy_on_write")
and get_option("mode.data_manager") == "block"
)
and len(self) == len(ref)
and self.name in ref.columns
):
elif len(self) == len(ref) and self.name in ref.columns:
# GH#42530 self.name must be in ref.columns
# to ensure column still in dataframe
# otherwise, either self or ref has swapped in new arrays
Expand Down