Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
pd.options.mode.copy_on_write = True
df = pd.DataFrame({"a": [1, 2, 3]})
df
a | |
---|---|
0 | 1 |
1 | 2 |
2 | 3 |
s = df["a"]
s
0 1
1 2
2 3
Name: a, dtype: int64
i = df.index
i.name = "new name"
df
a | |
---|---|
new name | |
0 | 1 |
1 | 2 |
2 | 3 |
s
new name
0 1
1 2
2 3
Name: a, dtype: int64
Issue Description
When turning on Copy-on-Write mode, I notice that index labels are some remaining shared mutable state across Series and DataFrame (and Index).
At a minimum, I'd expect the mutated index label not to affect the series "s" in the code example.
Potentially, the mutated index label wouldn't affect DataFrame either, but I could see some benefits to keeping that shared mutable state around.
Expected Behavior
Once a Series is constructed, it's index label is independent of that from the original DataFrame.
Installed Versions
INSTALLED VERSIONS
commit : 965ceca
python : 3.10.9.final.0
python-bits : 64
OS : Darwin
OS-release : 22.5.0
Version : Darwin Kernel Version 22.5.0: Mon Apr 24 20:51:50 PDT 2023; root:xnu-8796.121.2~5/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.2
numpy : 1.23.1
pytz : 2022.1
dateutil : 2.8.2
setuptools : 67.6.1
pip : 22.2
Cython : None
pytest : 7.3.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli :
fastparquet : None
fsspec : 2022.10.0
gcsfs : None
matplotlib : 3.5.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : 0.19.1
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : 1.4.42
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.3.0
pyqt5 : None