Skip to content

Commit 3cf05db

Browse files
authored
CoW: Avoid warning for ArrowDtypes when setting inplace (#56215)
1 parent df913e7 commit 3cf05db

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

pandas/core/internals/managers.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@
5454
)
5555

5656
import pandas.core.algorithms as algos
57-
from pandas.core.arrays import DatetimeArray
57+
from pandas.core.arrays import (
58+
ArrowExtensionArray,
59+
ArrowStringArray,
60+
DatetimeArray,
61+
)
5862
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
5963
from pandas.core.construction import (
6064
ensure_wrapped_if_datetimelike,
@@ -1322,11 +1326,15 @@ def column_setitem(
13221326
intermediate Series at the DataFrame level (`s = df[loc]; s[idx] = value`)
13231327
"""
13241328
if warn_copy_on_write() and not self._has_no_reference(loc):
1325-
warnings.warn(
1326-
COW_WARNING_GENERAL_MSG,
1327-
FutureWarning,
1328-
stacklevel=find_stack_level(),
1329-
)
1329+
if not isinstance(
1330+
self.blocks[self.blknos[loc]].values,
1331+
(ArrowExtensionArray, ArrowStringArray),
1332+
):
1333+
warnings.warn(
1334+
COW_WARNING_GENERAL_MSG,
1335+
FutureWarning,
1336+
stacklevel=find_stack_level(),
1337+
)
13301338
elif using_copy_on_write() and not self._has_no_reference(loc):
13311339
blkno = self.blknos[loc]
13321340
# Split blocks to only copy the column we want to modify

pandas/tests/copy_view/test_interp_fillna.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,9 @@ def test_fillna_inplace_ea_noop_shares_memory(
344344
assert not df._mgr._has_no_reference(1)
345345
assert not view._mgr._has_no_reference(1)
346346

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

0 commit comments

Comments
 (0)