From 2fa4bbd5e1b72285e6097255e7326b9b57424efb Mon Sep 17 00:00:00 2001 From: Vineet Kumar Date: Sun, 7 Dec 2025 22:10:37 +0530 Subject: [PATCH 1/3] DOC: clarify behavior of shallow copy with Copy-on-Write in NDFrame docstring --- pandas/core/generic.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 955ccf1492fa0..328bdedae3947 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6542,23 +6542,18 @@ def copy(self, deep: bool = True) -> Self: When ``deep=False``, a new object will be created without copying the calling object's data or index (only references to the data - and index are copied). Any changes to the data of the original - will be reflected in the shallow copy (and vice versa). + and index are copied). With Copy-on-Write enabled by default, + changes to the data of the original will *not* be reflected in the + shallow copy (and vice versa). The shallow copy uses a lazy (deferred) + copy mechanism that copies the data only when any changes to the + original or shallow copy are made, ensuring memory efficiency while + maintaining data integrity. .. note:: - The ``deep=False`` behaviour as described above will change - in pandas 3.0. `Copy-on-Write - `__ - will be enabled by default, which means that the "shallow" copy - is that is returned with ``deep=False`` will still avoid making - an eager copy, but changes to the data of the original will *no* - longer be reflected in the shallow copy (or vice versa). Instead, - it makes use of a lazy (deferred) copy mechanism that will copy - the data only when any changes to the original or shallow copy is - made. - - You can already get the future behavior and improvements through - enabling copy on write ``pd.options.mode.copy_on_write = True`` + In pandas versions prior to 3.0, the default behavior without + Copy-on-Write was different: changes to the data of the original + *were* reflected in the shallow copy (and vice versa). See the + :ref:`Copy-on-Write user guide ` for more information. Parameters ---------- From ff1e706c22dff2f7897df1c9a1a35c887efbf119 Mon Sep 17 00:00:00 2001 From: Vineet Kumar Date: Sun, 7 Dec 2025 23:54:58 +0530 Subject: [PATCH 2/3] DOC: improve clarity of Copy-on-Write --- pandas/core/generic.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 328bdedae3947..3eb287d92435f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6542,12 +6542,11 @@ def copy(self, deep: bool = True) -> Self: When ``deep=False``, a new object will be created without copying the calling object's data or index (only references to the data - and index are copied). With Copy-on-Write enabled by default, - changes to the data of the original will *not* be reflected in the - shallow copy (and vice versa). The shallow copy uses a lazy (deferred) - copy mechanism that copies the data only when any changes to the - original or shallow copy are made, ensuring memory efficiency while - maintaining data integrity. + and index are copied). With Copy-on-Write, changes to the data of the + original will *not* be reflected in the shallow copy (and vice versa). + The shallow copy uses a lazy (deferred) copy mechanism that copies the + data only when any changes to the original or shallow copy are made, + ensuring memory efficiency while maintaining data integrity. .. note:: In pandas versions prior to 3.0, the default behavior without From 2954d07e0a1583b986079b9a4167e8c82eeecb81 Mon Sep 17 00:00:00 2001 From: Vineet Kumar Date: Mon, 8 Dec 2025 20:50:06 +0530 Subject: [PATCH 3/3] DOC: improve clarity of Copy-on-Write explanation --- pandas/core/generic.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3eb287d92435f..59f3a5c1a7c55 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6542,17 +6542,17 @@ def copy(self, deep: bool = True) -> Self: When ``deep=False``, a new object will be created without copying the calling object's data or index (only references to the data - and index are copied). With Copy-on-Write, changes to the data of the - original will *not* be reflected in the shallow copy (and vice versa). - The shallow copy uses a lazy (deferred) copy mechanism that copies the + and index are copied). With Copy-on-Write, changes to the original + will *not* be reflected in the shallow copy (and vice versa). The + shallow copy uses a lazy (deferred) copy mechanism that copies the data only when any changes to the original or shallow copy are made, ensuring memory efficiency while maintaining data integrity. .. note:: In pandas versions prior to 3.0, the default behavior without - Copy-on-Write was different: changes to the data of the original - *were* reflected in the shallow copy (and vice versa). See the - :ref:`Copy-on-Write user guide ` for more information. + Copy-on-Write was different: changes to the original *were* reflected + in the shallow copy (and vice versa). See the :ref:`Copy-on-Write + user guide ` for more information. Parameters ----------