File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -6590,6 +6590,13 @@ def copy(self, deep: bool_t | None = True) -> Self:
6590
6590
:ref:`gotchas <gotchas.thread-safety>` when copying in a threading
6591
6591
environment.
6592
6592
6593
+ When ``copy_on_write`` in pandas config is set to ``True``, the
6594
+ ``copy_on_write`` config takes effect even when ``deep=False``.
6595
+ This means that any changes to the copied data would make a new copy
6596
+ of the data upon write (and vice versa). Changes made to either the
6597
+ original or copied variable would not be reflected in the counterpart.
6598
+ See :ref:`Copy_on_Write <copy_on_write>` for more information.
6599
+
6593
6600
Examples
6594
6601
--------
6595
6602
>>> s = pd.Series([1, 2], index=["a", "b"])
@@ -6657,6 +6664,21 @@ def copy(self, deep: bool_t | None = True) -> Self:
6657
6664
0 [10, 2]
6658
6665
1 [3, 4]
6659
6666
dtype: object
6667
+
6668
+ ** Copy-on-Write is set to true: **
6669
+
6670
+ >>> with pd.option_context("mode.copy_on_write", True):
6671
+ ... s = pd.Series([1, 2], index=["a", "b"])
6672
+ ... copy = s.copy(deep=False)
6673
+ ... s.iloc[0] = 100
6674
+ ... s
6675
+ a 100
6676
+ b 2
6677
+ dtype: int64
6678
+ >>> copy
6679
+ a 1
6680
+ b 2
6681
+ dtype: int64
6660
6682
"""
6661
6683
data = self ._mgr .copy (deep = deep )
6662
6684
self ._clear_item_cache ()
You can’t perform that action at this time.
0 commit comments