Skip to content

Commit 27e7467

Browse files
authored
DOC: Add note about copy on write improvements (#50471)
* DOC: Add note about copy on write improvements * Add gh reference * Add cow
1 parent 65baa5b commit 27e7467

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

doc/source/whatsnew/v2.0.0.rst

+41
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,47 @@ be set to ``"pyarrow"`` to return pyarrow-backed, nullable :class:`ArrowDtype` (
8282
df_pyarrow = pd.read_csv(data, use_nullable_dtypes=True, engine="pyarrow")
8383
df_pyarrow.dtypes
8484
85+
Copy on write improvements
86+
^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
88+
A new lazy copy mechanism that defers the copy until the object in question is modified
89+
was added to the following methods:
90+
91+
- :meth:`DataFrame.reset_index` / :meth:`Series.reset_index`
92+
- :meth:`DataFrame.set_index` / :meth:`Series.set_index`
93+
- :meth:`DataFrame.set_axis` / :meth:`Series.set_axis`
94+
- :meth:`DataFrame.rename_axis` / :meth:`Series.rename_axis`
95+
- :meth:`DataFrame.rename_columns`
96+
- :meth:`DataFrame.reindex` / :meth:`Series.reindex`
97+
- :meth:`DataFrame.reindex_like` / :meth:`Series.reindex_like`
98+
- :meth:`DataFrame.assign`
99+
- :meth:`DataFrame.drop`
100+
- :meth:`DataFrame.dropna` / :meth:`Series.dropna`
101+
- :meth:`DataFrame.select_dtypes`
102+
- :meth:`DataFrame.align` / :meth:`Series.align`
103+
- :meth:`Series.to_frame`
104+
- :meth:`DataFrame.rename` / :meth:`Series.rename`
105+
- :meth:`DataFrame.add_prefix` / :meth:`Series.add_prefix`
106+
- :meth:`DataFrame.add_suffix` / :meth:`Series.add_suffix`
107+
- :meth:`DataFrame.drop_duplicates` / :meth:`Series.drop_duplicates`
108+
- :meth:`DataFrame.reorder_levels` / :meth:`Series.reorder_levels`
109+
110+
These methods return views when copy on write is enabled, which provides a significant
111+
performance improvement compared to the regular execution (:issue:`49473`). Copy on write
112+
can be enabled through
113+
114+
.. code-block:: python
115+
116+
pd.set_option("mode.copy_on_write", True)
117+
pd.options.mode.copy_on_write = True
118+
119+
Alternatively, copy on write can be enabled locally through:
120+
121+
.. code-block:: python
122+
123+
with pd.option_context("mode.copy_on_write", True):
124+
...
125+
85126
.. _whatsnew_200.enhancements.other:
86127

87128
Other enhancements

0 commit comments

Comments
 (0)