Skip to content
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

CoW: Avoid warning for ArrowDtypes when setting inplace #56215

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 14 additions & 6 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
)

import pandas.core.algorithms as algos
from pandas.core.arrays import DatetimeArray
from pandas.core.arrays import (
ArrowExtensionArray,
ArrowStringArray,
DatetimeArray,
)
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
from pandas.core.construction import (
ensure_wrapped_if_datetimelike,
Expand Down Expand Up @@ -1343,11 +1347,15 @@ def column_setitem(
intermediate Series at the DataFrame level (`s = df[loc]; s[idx] = value`)
"""
if warn_copy_on_write() and not self._has_no_reference(loc):
warnings.warn(
COW_WARNING_GENERAL_MSG,
FutureWarning,
stacklevel=find_stack_level(),
)
if not isinstance(
self.blocks[self.blknos[loc]].values,
(ArrowExtensionArray, ArrowStringArray),
):
warnings.warn(
COW_WARNING_GENERAL_MSG,
FutureWarning,
stacklevel=find_stack_level(),
)
elif using_copy_on_write() and not self._has_no_reference(loc):
blkno = self.blknos[loc]
# Split blocks to only copy the column we want to modify
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/copy_view/test_interp_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ def test_fillna_inplace_ea_noop_shares_memory(
assert not df._mgr._has_no_reference(1)
assert not view._mgr._has_no_reference(1)

# TODO(CoW-warn) should this warn for ArrowDtype?
with tm.assert_cow_warning(warn_copy_on_write):
with tm.assert_cow_warning(
warn_copy_on_write and "pyarrow" not in any_numeric_ea_and_arrow_dtype
):
df.iloc[0, 1] = 100
if isinstance(df["a"].dtype, ArrowDtype) or using_copy_on_write:
tm.assert_frame_equal(df_orig, view)
Expand Down
Loading