-
-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Setting values on a multiindex df, via loc, does nothing on 1.4.x #46983
Comments
Hi @simonjayhawkins, Which one is considered the buggy behaviour? As a user, I would expect the former behaviour, from 1.3.5, where .loc actually modifies values. |
In general I would recommend to avoid chained indexing and use
|
As a workaround, I would suggest using either df.loc[pd.IndexSlice["A", :], "val1"] = 1 or df.loc[("A",), "val1"] = 1 to make the code more robust if column names also appear in the levels of the MultiIndex.
both
yes. this should raise a warning if we decide not to revert to the 1.3.5 behavior |
moving to 1.4.4 |
removing 1.4.x milestone |
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
Issue Description
On Pandas 1.4.x (including 1.4.2), the example code does not modify df. The value
1
is not assigned.It returns:
(This bug could be linked to #46837)
Expected Behavior
on Pandas 1.3.5, the example returns:
Installed Versions
INSTALLED VERSIONS
commit : 4bfe3d0
python : 3.8.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19042
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252
pandas : 1.4.2
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
pip : 22.0.4
setuptools : 56.0.0
Cython : None
pytest : 7.1.1
hypothesis : None
sphinx : 4.5.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.1
IPython : 8.2.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.5.1
numba : None
numexpr : 2.8.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: