Skip to content

Commit 02a2479

Browse files
committed
CoW: Avoid warning for ArrowDtypes when setting inplace
1 parent 44c2d1e commit 02a2479

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,
@@ -1343,11 +1347,15 @@ def column_setitem(
13431347
intermediate Series at the DataFrame level (`s = df[loc]; s[idx] = value`)
13441348
"""
13451349
if warn_copy_on_write() and not self._has_no_reference(loc):
1346-
warnings.warn(
1347-
COW_WARNING_GENERAL_MSG,
1348-
FutureWarning,
1349-
stacklevel=find_stack_level(),
1350-
)
1350+
if not isinstance(
1351+
self.blocks[self.blknos[loc]].values,
1352+
(ArrowExtensionArray, ArrowStringArray),
1353+
):
1354+
warnings.warn(
1355+
COW_WARNING_GENERAL_MSG,
1356+
FutureWarning,
1357+
stacklevel=find_stack_level(),
1358+
)
13511359
elif using_copy_on_write() and not self._has_no_reference(loc):
13521360
blkno = self.blknos[loc]
13531361
# 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)