Skip to content

Commit 38ac713

Browse files
authored
CLN: Misc pre-COW stuff (#57406)
* Remove assert_cow_warning * Remove misc COW stuff * Undo todo
1 parent de611a7 commit 38ac713

File tree

11 files changed

+2
-91
lines changed

11 files changed

+2
-91
lines changed

pandas/_testing/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
get_obj,
7373
)
7474
from pandas._testing.contexts import (
75-
assert_cow_warning,
7675
decompress_file,
7776
ensure_clean,
7877
raises_chained_assignment_error,
@@ -583,7 +582,6 @@ def shares_memory(left, right) -> bool:
583582
"assert_series_equal",
584583
"assert_sp_array_equal",
585584
"assert_timedelta_array_equal",
586-
"assert_cow_warning",
587585
"at",
588586
"BOOL_DTYPES",
589587
"box_expected",

pandas/_testing/contexts.py

-26
Original file line numberDiff line numberDiff line change
@@ -228,29 +228,3 @@ def raises_chained_assignment_error(warn=True, extra_warnings=(), extra_match=()
228228
warning,
229229
match="|".join((match, *extra_match)),
230230
)
231-
232-
233-
def assert_cow_warning(warn=True, match=None, **kwargs):
234-
"""
235-
Assert that a warning is raised in the CoW warning mode.
236-
237-
Parameters
238-
----------
239-
warn : bool, default True
240-
By default, check that a warning is raised. Can be turned off by passing False.
241-
match : str
242-
The warning message to match against, if different from the default.
243-
kwargs
244-
Passed through to assert_produces_warning
245-
"""
246-
from pandas._testing import assert_produces_warning
247-
248-
if not warn:
249-
from contextlib import nullcontext
250-
251-
return nullcontext()
252-
253-
if not match:
254-
match = "Setting a value on a view"
255-
256-
return assert_produces_warning(FutureWarning, match=match, **kwargs)

pandas/core/internals/blocks.py

-23
Original file line numberDiff line numberDiff line change
@@ -131,29 +131,6 @@
131131
_dtype_obj = np.dtype("object")
132132

133133

134-
COW_WARNING_GENERAL_MSG = """\
135-
Setting a value on a view: behaviour will change in pandas 3.0.
136-
You are mutating a Series or DataFrame object, and currently this mutation will
137-
also have effect on other Series or DataFrame objects that share data with this
138-
object. In pandas 3.0 (with Copy-on-Write), updating one Series or DataFrame object
139-
will never modify another.
140-
"""
141-
142-
143-
COW_WARNING_SETITEM_MSG = """\
144-
Setting a value on a view: behaviour will change in pandas 3.0.
145-
Currently, the mutation will also have effect on the object that shares data
146-
with this object. For example, when setting a value in a Series that was
147-
extracted from a column of a DataFrame, that DataFrame will also be updated:
148-
149-
ser = df["col"]
150-
ser[0] = 0 <--- in pandas 2, this also updates `df`
151-
152-
In pandas 3.0 (with Copy-on-Write), updating one Series/DataFrame will never
153-
modify another, and thus in the example above, `df` will not be changed.
154-
"""
155-
156-
157134
def maybe_split(meth: F) -> F:
158135
"""
159136
If we have a multi-column block, split and operate block-wise. Otherwise

pandas/errors/cow.py

-30
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,3 @@
2222
"using 'df.method({col: value}, inplace=True)' instead, to perform "
2323
"the operation inplace on the original object.\n\n"
2424
)
25-
26-
27-
_chained_assignment_warning_msg = (
28-
"ChainedAssignmentError: behaviour will change in pandas 3.0!\n"
29-
"You are setting values through chained assignment. Currently this works "
30-
"in certain cases, but when using Copy-on-Write (which will become the "
31-
"default behaviour in pandas 3.0) this will never work to update the "
32-
"original DataFrame or Series, because the intermediate object on which "
33-
"we are setting values will behave as a copy.\n"
34-
"A typical example is when you are setting values in a column of a "
35-
"DataFrame, like:\n\n"
36-
'df["col"][row_indexer] = value\n\n'
37-
'Use `df.loc[row_indexer, "col"] = values` instead, to perform the '
38-
"assignment in a single step and ensure this keeps updating the original `df`.\n\n"
39-
"See the caveats in the documentation: "
40-
"https://pandas.pydata.org/pandas-docs/stable/user_guide/"
41-
"indexing.html#returning-a-view-versus-a-copy\n"
42-
)
43-
44-
_chained_assignment_warning_method_msg = (
45-
"A value is trying to be set on a copy of a DataFrame or Series "
46-
"through chained assignment using an inplace method.\n"
47-
"The behavior will change in pandas 3.0. This inplace method will "
48-
"never work because the intermediate object on which we are setting "
49-
"values always behaves as a copy.\n\n"
50-
"For example, when doing 'df[col].method(value, inplace=True)', try "
51-
"using 'df.method({col: value}, inplace=True)' or "
52-
"df[col] = df[col].method(value) instead, to perform "
53-
"the operation inplace on the original object.\n\n"
54-
)

pandas/tests/copy_view/test_chained_assignment_deprecation.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pandas._testing as tm
88

99

10-
# TODO(CoW-warn) expand the cases
1110
@pytest.mark.parametrize(
1211
"indexer", [0, [0, 1], slice(0, 2), np.array([True, False, True])]
1312
)

pandas/tests/copy_view/test_core_functionalities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_setitem_with_view_invalidated_does_not_copy(request):
4646
df["b"] = 100
4747
arr = get_array(df, "a")
4848
view = None # noqa: F841
49-
# TODO(CoW-warn) false positive? -> block gets split because of `df["b"] = 100`
49+
# TODO(CoW) block gets split because of `df["b"] = 100`
5050
# which introduces additional refs, even when those of `view` go out of scopes
5151
df.iloc[0, 0] = 100
5252
# Setitem split the block. Since the old block shared data with view

pandas/tests/extension/json/test_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_fillna_copy_frame(self, data_missing):
218218
super().test_fillna_copy_frame(data_missing)
219219

220220
@pytest.mark.xfail(reason="Fails with CoW")
221-
def test_equals_same_data_different_object(self, data, request):
221+
def test_equals_same_data_different_object(self, data):
222222
super().test_equals_same_data_different_object(data)
223223

224224
@pytest.mark.xfail(reason="failing on np.array(self, dtype=str)")

pandas/tests/frame/indexing/test_indexing.py

-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ def test_setitem(self, float_frame, using_infer_string):
321321
# so raise/warn
322322
smaller = float_frame[:2]
323323

324-
# With CoW, adding a new column doesn't raise a warning
325324
smaller["col10"] = ["1", "2"]
326325

327326
if using_infer_string:

pandas/tests/indexing/multiindex/test_setitem.py

-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ def test_multiindex_assignment_single_dtype(self):
207207
)
208208

209209
# arr can be losslessly cast to int, so this setitem is inplace
210-
# INFO(CoW-warn) this does not warn because we directly took .values
211-
# above, so no reference to a pandas object is alive for `view`
212210
df.loc[4, "c"] = arr
213211
exp = Series(arr, index=[8, 10], name="c", dtype="int64")
214212
result = df.loc[4, "c"]

pandas/tests/indexing/test_chaining_and_caching.py

-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ def test_detect_chained_assignment_warning_stacklevel(self, rhs):
324324
df = DataFrame(np.arange(25).reshape(5, 5))
325325
df_original = df.copy()
326326
chained = df.loc[:3]
327-
# INFO(CoW) no warning, and original dataframe not changed
328327
chained[2] = rhs
329328
tm.assert_frame_equal(df, df_original)
330329

scripts/validate_unwanted_patterns.py

-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@
4949
"_global_config",
5050
"_chained_assignment_msg",
5151
"_chained_assignment_method_msg",
52-
"_chained_assignment_warning_msg",
53-
"_chained_assignment_warning_method_msg",
54-
"_check_cacher",
5552
"_version_meson",
5653
# The numba extensions need this to mock the iloc object
5754
"_iLocIndexer",

0 commit comments

Comments
 (0)