Skip to content

Commit 7b51d3a

Browse files
authored
DOC: clarify behavior of shallow copy with Copy-on-Write in NDFrame docstring (#63291)
1 parent b43b95d commit 7b51d3a

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

pandas/core/generic.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6526,23 +6526,17 @@ def copy(self, deep: bool = True) -> Self:
65266526
65276527
When ``deep=False``, a new object will be created without copying
65286528
the calling object's data or index (only references to the data
6529-
and index are copied). Any changes to the data of the original
6530-
will be reflected in the shallow copy (and vice versa).
6529+
and index are copied). With Copy-on-Write, changes to the original
6530+
will *not* be reflected in the shallow copy (and vice versa). The
6531+
shallow copy uses a lazy (deferred) copy mechanism that copies the
6532+
data only when any changes to the original or shallow copy are made,
6533+
ensuring memory efficiency while maintaining data integrity.
65316534
65326535
.. note::
6533-
The ``deep=False`` behaviour as described above will change
6534-
in pandas 3.0. `Copy-on-Write
6535-
<https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
6536-
will be enabled by default, which means that the "shallow" copy
6537-
is that is returned with ``deep=False`` will still avoid making
6538-
an eager copy, but changes to the data of the original will *no*
6539-
longer be reflected in the shallow copy (or vice versa). Instead,
6540-
it makes use of a lazy (deferred) copy mechanism that will copy
6541-
the data only when any changes to the original or shallow copy is
6542-
made.
6543-
6544-
You can already get the future behavior and improvements through
6545-
enabling copy on write ``pd.options.mode.copy_on_write = True``
6536+
In pandas versions prior to 3.0, the default behavior without
6537+
Copy-on-Write was different: changes to the original *were* reflected
6538+
in the shallow copy (and vice versa). See the :ref:`Copy-on-Write
6539+
user guide <copy_on_write>` for more information.
65466540
65476541
Parameters
65486542
----------

0 commit comments

Comments
 (0)