Skip to content

Commit 1895c38

Browse files
authored
DEPR: unused Copy-on-Write option (#63231)
1 parent aa5726a commit 1895c38

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

ci/code_checks.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7272
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
7373
-i "pandas.Period.freq GL08" \
7474
-i "pandas.Period.ordinal GL08" \
75+
-i "pandas.errors.ChainedAssignmentError SA01" \
7576
-i "pandas.errors.IncompatibleFrequency SA01,SS06,EX01" \
7677
-i "pandas.api.extensions.ExtensionArray.value_counts EX01,RT03,SA01" \
7778
-i "pandas.api.typing.DataFrameGroupBy.plot PR02" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ process in more detail.
117117

118118
`PDEP-7: Consistent copy/view semantics in pandas with Copy-on-Write <https://pandas.pydata.org/pdeps/0007-copy-on-write.html>`__
119119

120+
Setting the option ``mode.copy_on_write`` no longer has any impact. The option is deprecated
121+
and will be removed in pandas 4.0.
122+
120123
.. _whatsnew_300.enhancements.col:
121124

122125
``pd.col`` syntax can now be used in :meth:`DataFrame.assign` and :meth:`DataFrame.loc`

pandas/core/config_init.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,11 @@ def is_terminal() -> bool:
408408
cf.register_option("sim_interactive", False, tc_sim_interactive_doc)
409409

410410

411-
# TODO better name?
412411
copy_on_write_doc = """
413412
: bool
414-
Use new copy-view behaviour using Copy-on-Write. Defaults to False,
415-
unless overridden by the 'PANDAS_COPY_ON_WRITE' environment variable
416-
(if set to "1" for True, needs to be set before pandas is imported).
413+
Use new copy-view behaviour using Copy-on-Write. No longer used,
414+
pandas now always uses Copy-on-Write behavior. This option will
415+
be removed in pandas 4.0.
417416
"""
418417

419418

@@ -902,3 +901,11 @@ def register_converter_cb(key: str) -> None:
902901

903902
# GH#59502
904903
cf.deprecate_option("future.no_silent_downcasting", Pandas4Warning)
904+
cf.deprecate_option(
905+
"mode.copy_on_write",
906+
Pandas4Warning,
907+
msg=(
908+
"Copy-on-Write can no longer be disabled, setting to False has no impact. "
909+
"This option will be removed in pandas 4.0."
910+
),
911+
)

pandas/errors/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ class ChainedAssignmentError(Warning):
668668
"""
669669
Warning raised when trying to set using chained assignment.
670670
671-
When the ``mode.copy_on_write`` option is enabled, chained assignment can
671+
With Copy-on-Write now always enabled, chained assignment can
672672
never work. In such a situation, we are always setting into a temporary
673673
object that is the result of an indexing operation (getitem), which under
674674
Copy-on-Write always behaves as a copy. Thus, assigning through a chain
@@ -677,18 +677,11 @@ class ChainedAssignmentError(Warning):
677677
For more information on Copy-on-Write,
678678
see :ref:`the user guide<copy_on_write>`.
679679
680-
See Also
681-
--------
682-
options.mode.copy_on_write : Global setting for enabling or disabling
683-
Copy-on-Write behavior.
684-
685680
Examples
686681
--------
687-
>>> pd.options.mode.copy_on_write = True
688682
>>> df = pd.DataFrame({"A": [1, 1, 1, 2, 2]}, columns=["A"])
689683
>>> df["A"][0:3] = 10 # doctest: +SKIP
690684
... # ChainedAssignmentError: ...
691-
>>> pd.options.mode.copy_on_write = False
692685
"""
693686

694687

pandas/tests/copy_view/test_copy_deprecation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,12 @@ def test_copy_deprecation_merge_concat():
8989
Pandas4Warning, match="copy", check_stacklevel=False
9090
):
9191
concat([df, df], copy=False)
92+
93+
94+
@pytest.mark.parametrize("value", [False, True, "warn"])
95+
def test_copy_on_write_deprecation_option(value):
96+
msg = "Copy-on-Write can no longer be disabled"
97+
# stacklevel points to contextlib due to use of context manager.
98+
with tm.assert_produces_warning(Pandas4Warning, match=msg, check_stacklevel=False):
99+
with pd.option_context("mode.copy_on_write", value):
100+
pass

0 commit comments

Comments
 (0)