From db0da04c9b8559e3eac8c77d9e1a1e0332a57a43 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Wed, 28 Dec 2022 20:47:23 +0100 Subject: [PATCH 1/3] DOC: Add note about copy on write improvements --- doc/source/whatsnew/v2.0.0.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 0ef5636a97d40..e6028df8ee8be 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -77,6 +77,34 @@ be set to ``"pyarrow"`` to return pyarrow-backed, nullable :class:`ArrowDtype` ( df_pyarrow = pd.read_csv(data, use_nullable_dtypes=True, engine="pyarrow") df_pyarrow.dtypes +Copy on write improvements +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A new lazy copy mechanism that defers the copy until the object in question is modified +was added to the following methods: + +- :meth:`DataFrame.reset_index` / :meth:`Series.reset_index` +- :meth:`DataFrame.set_index` / :meth:`Series.set_index` +- :meth:`DataFrame.set_axis` / :meth:`Series.set_axis` +- :meth:`DataFrame.rename_axis` / :meth:`Series.rename_axis` +- :meth:`DataFrame.rename_columns` +- :meth:`DataFrame.reindex` / :meth:`Series.reindex` +- :meth:`DataFrame.reindex_like` / :meth:`Series.reindex_like` +- :meth:`DataFrame.assign` +- :meth:`DataFrame.drop` +- :meth:`DataFrame.dropna` / :meth:`Series.dropna` +- :meth:`DataFrame.select_dtypes` +- :meth:`DataFrame.align` / :meth:`Series.align` +- ::meth:`Series.to_frame` +- :meth:`DataFrame.rename` / :meth:`Series.rename` +- :meth:`DataFrame.add_prefix` / :meth:`Series.add_prefix` +- :meth:`DataFrame.add_suffix` / :meth:`Series.add_suffix` +- :meth:`DataFrame.drop_duplicates` / :meth:`Series.drop_duplicates` +- :meth:`DataFrame.reorder_levels` / :meth:`Series.reorder_levels` + +These methods return views when copy on write is enabled, which provides a significant +performance improvement compared to the regular execution. + .. _whatsnew_200.enhancements.other: Other enhancements From 8c99a90fd4aa5842709706bae48704832ccffe03 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Thu, 29 Dec 2022 21:10:01 +0100 Subject: [PATCH 2/3] Add gh reference --- doc/source/whatsnew/v2.0.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 42c0392ce160b..954f48abea4b5 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -95,7 +95,7 @@ was added to the following methods: - :meth:`DataFrame.dropna` / :meth:`Series.dropna` - :meth:`DataFrame.select_dtypes` - :meth:`DataFrame.align` / :meth:`Series.align` -- ::meth:`Series.to_frame` +- :meth:`Series.to_frame` - :meth:`DataFrame.rename` / :meth:`Series.rename` - :meth:`DataFrame.add_prefix` / :meth:`Series.add_prefix` - :meth:`DataFrame.add_suffix` / :meth:`Series.add_suffix` @@ -103,7 +103,7 @@ was added to the following methods: - :meth:`DataFrame.reorder_levels` / :meth:`Series.reorder_levels` These methods return views when copy on write is enabled, which provides a significant -performance improvement compared to the regular execution. +performance improvement compared to the regular execution (:issue:`49473`). .. _whatsnew_200.enhancements.other: From 785cb6c583a536b9ecca7b250e5ebfa2ad3d51c6 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 3 Jan 2023 22:55:04 +0100 Subject: [PATCH 3/3] Add cow --- doc/source/whatsnew/v2.0.0.rst | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 0c15efaa56876..a01c31cd614b0 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -103,7 +103,20 @@ was added to the following methods: - :meth:`DataFrame.reorder_levels` / :meth:`Series.reorder_levels` These methods return views when copy on write is enabled, which provides a significant -performance improvement compared to the regular execution (:issue:`49473`). +performance improvement compared to the regular execution (:issue:`49473`). Copy on write +can be enabled through + +.. code-block:: python + + pd.set_option("mode.copy_on_write", True) + pd.options.mode.copy_on_write = True + +Alternatively, copy on write can be enabled locally through: + +.. code-block:: python + + with pd.option_context("mode.copy_on_write", True): + ... .. _whatsnew_200.enhancements.other: