Skip to content

DEP: Deprecate CoW and no_silent_downcasting options #57872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 12 additions & 6 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,19 @@ Without copy on write, the parent :class:`DataFrame` is updated when updating a

With copy on write enabled, df won't be updated anymore:

.. ipython:: python
.. code-block:: python

with pd.option_context("mode.copy_on_write", True):
df = pd.DataFrame({"foo": [1, 2, 3], "bar": 1})
view = df["foo"]
view.iloc[0]
df
In [2]: with pd.option_context("mode.copy_on_write", True):
...: df = pd.DataFrame({"foo": [1, 2, 3], "bar": 1})
...: view = df["foo"]
...: view.iloc[0]
...: df

Out[3]:
foo bar
0 1 1
1 2 1
2 3 1

A more detailed explanation can be found `here <https://phofl.github.io/cow-introduction.html>`_.

Expand Down
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ Other Deprecations
- Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`)
- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`)
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)
-
- Deprecated the option ``future.no_silent_downcasting``. The opt-in behavior from the 2.x release series is already the default and this option has no effect anymore (:issue:`57872`)
- Deprecated the option ``mode.copy_on_write``. Copy-on-Write is already the default and this option has no effect anymore (:issue:`57872`)

.. ---------------------------------------------------------------------------
.. _whatsnew_300.prior_deprecations:
Expand Down
15 changes: 15 additions & 0 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

__docformat__ = "restructuredtext"

import os
import warnings

# Let users know if they're missing any of our hard dependencies
_hard_dependencies = ("numpy", "pytz", "dateutil")
_missing_dependencies = []
Expand Down Expand Up @@ -190,6 +193,18 @@
del get_versions, v


if "PANDAS_COPY_ON_WRITE" in os.environ:
warnings.warn(
"The env variable PANDAS_COPY_ON_WRITE is set. The copy_on_write option is "
"deprecated and will be removed in a future version. Copy-on-Write "
"is already enabled by default.",
FutureWarning,
stacklevel=2,
)

del os, warnings


# module level doc-string
__doc__ = """
pandas - a powerful data analysis and manipulation library for Python
Expand Down
18 changes: 18 additions & 0 deletions pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,3 +875,21 @@ def register_converter_cb(key: str) -> None:
"(at which point this option will be deprecated).",
validator=is_one_of_factory([True, False]),
)


cf.deprecate_option(
# GH#55043
"mode.copy_on_write",
"copy_on_write option is deprecated and will be removed in a future "
"version. Copy-on-Write is already enabled; this option has no effect "
"anymore.",
)


cf.deprecate_option(
# GH#55043
"future.no_silent_downcasting",
"no_silent_downcasting option is deprecated and will be removed in a future "
"version. The deprecation is enforced and this option doesn't have any effect "
"anymore.",
)
2 changes: 0 additions & 2 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,9 @@ class ChainedAssignmentError(Warning):

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
24 changes: 24 additions & 0 deletions pandas/tests/copy_view/test_option_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import importlib

import pytest

import pandas as pd
import pandas._testing as tm


def test_configs_deprecated():
# GH#57872
with tm.assert_produces_warning(FutureWarning, match="is deprecated"):
pd.options.mode.copy_on_write = True

with tm.assert_produces_warning(FutureWarning, match="is deprecated"):
pd.options.future.no_silent_downcasting = True


def test_env_variable():
# GH#57872
pytest.MonkeyPatch().setenv("PANDAS_COPY_ON_WRITE", "1")
with tm.assert_produces_warning(
FutureWarning, match="deprecated", check_stacklevel=False
):
importlib.reload(pd)
4 changes: 1 addition & 3 deletions pandas/tests/strings/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
MultiIndex,
Series,
_testing as tm,
option_context,
)
from pandas.core.strings.accessor import StringMethods

Expand Down Expand Up @@ -164,8 +163,7 @@ def test_api_per_method(

if inferred_dtype in allowed_types:
# xref GH 23555, GH 23556
with option_context("future.no_silent_downcasting", True):
method(*args, **kwargs) # works!
method(*args, **kwargs) # works!
else:
# GH 23011, GH 23163
msg = (
Expand Down