diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 43aa63c284f38..d4c4899dfbf17 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -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 `_. diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index fb33601263c5d..89fe9a1bed5c7 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -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: diff --git a/pandas/__init__.py b/pandas/__init__.py index 3ee6f6abf97bf..4955eaecf2fee 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -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 = [] @@ -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 diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 46c9139c3456c..b2fb20c550656 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -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.", +) diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py index 402bbdb872a18..8ef190bbdcd39 100644 --- a/pandas/errors/__init__.py +++ b/pandas/errors/__init__.py @@ -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 """ diff --git a/pandas/tests/copy_view/test_option_deprecation.py b/pandas/tests/copy_view/test_option_deprecation.py new file mode 100644 index 0000000000000..9e790a6734126 --- /dev/null +++ b/pandas/tests/copy_view/test_option_deprecation.py @@ -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) diff --git a/pandas/tests/strings/test_api.py b/pandas/tests/strings/test_api.py index ff8c6a98e1819..194df11a6deb6 100644 --- a/pandas/tests/strings/test_api.py +++ b/pandas/tests/strings/test_api.py @@ -8,7 +8,6 @@ MultiIndex, Series, _testing as tm, - option_context, ) from pandas.core.strings.accessor import StringMethods @@ -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 = (