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
A = pd.DataFrame({'a':[False,True]}) # index=[0,1] vs index=range(2)
A['i'] = A.index
A.loc[A['a'],'i'] = -2
print(A.loc[A['a'],:])
Issue Description
when assign index(RangeIndex) to new column then change this column by loc, index will change unexpectedly. this issue exists in 1.4.x but not in 1.1.1
a | i | |
---|---|---|
-2 | True | -2 |
Expected Behavior
a | i | |
---|---|---|
1 | True | -2 |
Installed Versions
INSTALLED VERSIONS
commit : bb1f651
python : 3.9.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-110-generic
Version : #124-Ubuntu SMP Thu Apr 14 19:46:19 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.0
numpy : 1.22.2
pytz : 2022.1
dateutil : 2.8.2
pip : 21.2.3
setuptools : 49.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : 2.9.1
jinja2 : 3.1.2
IPython : 7.33.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.4.3
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.23
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
None