@@ -6686,6 +6686,21 @@ def copy(self, deep: bool_t | None = True) -> Self:
6686
6686
and index are copied). Any changes to the data of the original
6687
6687
will be reflected in the shallow copy (and vice versa).
6688
6688
6689
+ .. note::
6690
+ The ``deep=False`` behaviour as described above will change
6691
+ in pandas 3.0. `Copy-on-Write
6692
+ <https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
6693
+ will be enabled by default, which means that the "shallow" copy
6694
+ is that is returned with ``deep=False`` will still avoid making
6695
+ an eager copy, but changes to the data of the original will *no*
6696
+ longer be reflected in the shallow copy (or vice versa). Instead,
6697
+ it makes use of a lazy (deferred) copy mechanism that will copy
6698
+ the data only when any changes to the original or shallow copy is
6699
+ made.
6700
+
6701
+ You can already get the future behavior and improvements through
6702
+ enabling copy on write ``pd.options.mode.copy_on_write = True``
6703
+
6689
6704
Parameters
6690
6705
----------
6691
6706
deep : bool, default True
@@ -6755,7 +6770,8 @@ def copy(self, deep: bool_t | None = True) -> Self:
6755
6770
False
6756
6771
6757
6772
Updates to the data shared by shallow copy and original is reflected
6758
- in both; deep copy remains unchanged.
6773
+ in both (NOTE: this will no longer be true for pandas >= 3.0);
6774
+ deep copy remains unchanged.
6759
6775
6760
6776
>>> s.iloc[0] = 3
6761
6777
>>> shallow.iloc[1] = 4
@@ -6788,7 +6804,8 @@ def copy(self, deep: bool_t | None = True) -> Self:
6788
6804
1 [3, 4]
6789
6805
dtype: object
6790
6806
6791
- ** Copy-on-Write is set to true: **
6807
+ **Copy-on-Write is set to true**, the shallow copy is not modified
6808
+ when the original data is changed:
6792
6809
6793
6810
>>> with pd.option_context("mode.copy_on_write", True):
6794
6811
... s = pd.Series([1, 2], index=["a", "b"])
0 commit comments