Dataframe change alters original array used in creation · Issue #32960 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
a = pd.array([0, 1, 2]) df1 = pd.DataFrame({"col1": ['a', 'b', 'c'], "col2": a}) df1.loc[0, 'col2'] = 3
print(a)
[3, 1, 2] Length: 3, dtype: Int64Problem description
Pandas master has this strange change in behaviour when df created from array changes the original array if the value in the related column is changed. Pandas 1.0.3 does not alter the original array. It seems that it does a copy somewhere while master does not do that anymore.
I don't think the original array should be altered. Doing the same with list or np.array does not alter the original list/array either.
Expected Output
<IntegerArray>
[0, 1, 2]
Length: 3, dtype: Int64
Output of pd.show_versions()
INSTALLED VERSIONS
commit : d3e5485
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.3.0
Version : Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.0.dev0+944.gd3e54851b
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 41.6.0
Cython : 0.29.15
pytest : 5.4.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
matplotlib : 3.1.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.15
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None