Skip to content

Commit e16abb4

Browse files
address feedback
1 parent 7836601 commit e16abb4

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pandas/core/internals/managers.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1991,11 +1991,13 @@ def setitem_inplace(self, indexer, value, warn: bool = True) -> None:
19911991
in place, not returning a new Manager (and Block), and thus never changing
19921992
the dtype.
19931993
"""
1994-
if not self._has_no_reference(0):
1995-
if using_copy_on_write():
1994+
using_cow = using_copy_on_write()
1995+
warn_cow = warn_copy_on_write()
1996+
if using_cow or warn_cow and not self._has_no_reference(0):
1997+
if using_cow:
19961998
self.blocks = (self._block.copy(),)
19971999
self._cache.clear()
1998-
elif warn and warn_copy_on_write():
2000+
elif warn and warn_cow:
19992001
warnings.warn(
20002002
"Setting value on view: behaviour will change in pandas 3.0 "
20012003
"with Copy-on-Write ...",

pandas/tests/copy_view/test_indexing.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_subset_column_slice(
163163
assert not np.shares_memory(get_array(subset, "b"), get_array(df, "b"))
164164
else:
165165
# we only get a warning in case of a single block
166-
# TODO
166+
# TODO(CoW-warn) should warn
167167
warn = (
168168
SettingWithCopyWarning
169169
if (single_block and not warn_copy_on_write)
@@ -326,7 +326,7 @@ def test_subset_set_with_row_indexer(
326326
):
327327
pytest.skip("setitem with labels selects on columns")
328328

329-
# TODO
329+
# TODO(CoW-warn) should warn
330330
if using_copy_on_write or warn_copy_on_write:
331331
indexer_si(subset)[indexer] = 0
332332
else:
@@ -358,7 +358,7 @@ def test_subset_set_with_mask(backend, using_copy_on_write, warn_copy_on_write):
358358

359359
mask = subset > 3
360360

361-
# TODO
361+
# TODO(CoW-warn) should warn
362362
if using_copy_on_write or warn_copy_on_write:
363363
subset[mask] = 0
364364
else:
@@ -392,7 +392,7 @@ def test_subset_set_column(backend, using_copy_on_write, warn_copy_on_write):
392392
else:
393393
arr = pd.array([10, 11], dtype="Int64")
394394

395-
# TODO
395+
# TODO(CoW-warn) should warn
396396
if using_copy_on_write or warn_copy_on_write:
397397
subset["a"] = arr
398398
else:
@@ -493,7 +493,7 @@ def test_subset_set_columns(backend, using_copy_on_write, warn_copy_on_write, dt
493493
df_orig = df.copy()
494494
subset = df[1:3]
495495

496-
# TODO
496+
# TODO(CoW-warn) should warn
497497
if using_copy_on_write or warn_copy_on_write:
498498
subset[["a", "c"]] = 0
499499
else:
@@ -1004,7 +1004,7 @@ def test_column_as_series_no_item_cache(
10041004
else:
10051005
assert s1 is s2
10061006

1007-
# TODO
1007+
# TODO(CoW-warn) should warn
10081008
if using_copy_on_write or warn_copy_on_write or using_array_manager:
10091009
s1.iloc[0] = 0
10101010
else:

0 commit comments

Comments
 (0)