Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
-i "pandas.Period.freq GL08" \
-i "pandas.Period.ordinal GL08" \
-i "pandas.errors.ChainedAssignmentError SA01" \
-i "pandas.errors.IncompatibleFrequency SA01,SS06,EX01" \
-i "pandas.api.extensions.ExtensionArray.value_counts EX01,RT03,SA01" \
-i "pandas.api.typing.DataFrameGroupBy.plot PR02" \
Expand Down
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ process in more detail.

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

Setting the option ``mode.copy_on_write`` no longer has any impact. The option is deprecated
and will be removed in pandas 4.0.

.. _whatsnew_300.enhancements.col:

``pd.col`` syntax can now be used in :meth:`DataFrame.assign` and :meth:`DataFrame.loc`
Expand Down
15 changes: 11 additions & 4 deletions pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,11 @@ def is_terminal() -> bool:
cf.register_option("sim_interactive", False, tc_sim_interactive_doc)


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


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

# GH#59502
cf.deprecate_option("future.no_silent_downcasting", Pandas4Warning)
cf.deprecate_option(
"mode.copy_on_write",
Pandas4Warning,
msg=(
"Copy-on-Write can no longer be disabled, setting to False has no impact. "
"This option will be removed in pandas 4.0."
),
)
9 changes: 1 addition & 8 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ class ChainedAssignmentError(Warning):
"""
Warning raised when trying to set using chained assignment.

When the ``mode.copy_on_write`` option is enabled, chained assignment can
With Copy-on-Write now always enabled, chained assignment can
never work. In such a situation, we are always setting into a temporary
object that is the result of an indexing operation (getitem), which under
Copy-on-Write always behaves as a copy. Thus, assigning through a chain
Expand All @@ -677,18 +677,11 @@ class ChainedAssignmentError(Warning):
For more information on Copy-on-Write,
see :ref:`the user guide<copy_on_write>`.

See Also
--------
options.mode.copy_on_write : Global setting for enabling or disabling
Copy-on-Write behavior.

Examples
--------
>>> pd.options.mode.copy_on_write = True
>>> df = pd.DataFrame({"A": [1, 1, 1, 2, 2]}, columns=["A"])
>>> df["A"][0:3] = 10 # doctest: +SKIP
... # ChainedAssignmentError: ...
>>> pd.options.mode.copy_on_write = False
"""


Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/copy_view/test_copy_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ def test_copy_deprecation_merge_concat():
Pandas4Warning, match="copy", check_stacklevel=False
):
concat([df, df], copy=False)


@pytest.mark.parametrize("value", [False, True, "warn"])
def test_copy_on_write_deprecation_option(value):
msg = "Copy-on-Write can no longer be disabled"
with tm.assert_produces_warning(Pandas4Warning, match=msg):
pd.set_option("mode.copy_on_write", value)
Loading