Skip to content

Commit 2fa4bbd

Browse files
committed
DOC: clarify behavior of shallow copy with Copy-on-Write in NDFrame docstring
1 parent 311f92e commit 2fa4bbd

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

pandas/core/generic.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6542,23 +6542,18 @@ def copy(self, deep: bool = True) -> Self:
65426542
65436543
When ``deep=False``, a new object will be created without copying
65446544
the calling object's data or index (only references to the data
6545-
and index are copied). Any changes to the data of the original
6546-
will be reflected in the shallow copy (and vice versa).
6545+
and index are copied). With Copy-on-Write enabled by default,
6546+
changes to the data of the original will *not* be reflected in the
6547+
shallow copy (and vice versa). The shallow copy uses a lazy (deferred)
6548+
copy mechanism that copies the data only when any changes to the
6549+
original or shallow copy are made, ensuring memory efficiency while
6550+
maintaining data integrity.
65476551
65486552
.. note::
6549-
The ``deep=False`` behaviour as described above will change
6550-
in pandas 3.0. `Copy-on-Write
6551-
<https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
6552-
will be enabled by default, which means that the "shallow" copy
6553-
is that is returned with ``deep=False`` will still avoid making
6554-
an eager copy, but changes to the data of the original will *no*
6555-
longer be reflected in the shallow copy (or vice versa). Instead,
6556-
it makes use of a lazy (deferred) copy mechanism that will copy
6557-
the data only when any changes to the original or shallow copy is
6558-
made.
6559-
6560-
You can already get the future behavior and improvements through
6561-
enabling copy on write ``pd.options.mode.copy_on_write = True``
6553+
In pandas versions prior to 3.0, the default behavior without
6554+
Copy-on-Write was different: changes to the data of the original
6555+
*were* reflected in the shallow copy (and vice versa). See the
6556+
:ref:`Copy-on-Write user guide <copy_on_write>` for more information.
65626557
65636558
Parameters
65646559
----------

0 commit comments

Comments
 (0)