BUG: Update Values from MultiIndex Dataframe after using loc is not applied correctly · Issue #47867 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd import numpy as np

df = pd.DataFrame() df['idx1'] = [0,1,2,3,4] df['idx2'] = [0,1,2,3,4] df['abool'] = True df['a'] = np.arange(5, dtype='int64') df['b'] = np.arange(5, dtype='float64') df['c'] = np.arange(5, dtype='int64') df = df.set_index(['idx1','idx2'])

idx = [(1,1),(3,3)] df.loc[idx, 'c'] = 0 df.loc[idx, 'c']

df.loc[idx, ['a', 'b']] # This line is the problem

df.loc[idx, 'c'] = 15 df.loc[idx, 'c']

Issue Description

In Pandas 1.4.x the last line is not showing the change in the column c and the values still being 0.

>>> idx1  idx2
1     1       0
3     3       0
Name: c, dtype: int64

When I call the column c as DataFrame I get the correct values

df.loc[idx, ['c']]

>>>         c
idx1 idx2    
1    1     15
3    3     15

Expected Behavior

On Pandas 1.3.5 I get

>>> idx1  idx2
1     1       15
3     3       15
Name: c, dtype: int64

Installed Versions

INSTALLED VERSIONS

commit : 66e3805
python : 3.8.12.final.0
python-bits : 64
OS : Windows
OS-release : 7
Version : 6.1.7601
machine : AMD64
processor : Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Spanish_Chile.1252

pandas : 1.3.5
numpy : 1.23.1
pytz : 2022.1
dateutil : 2.8.2
pip : 22.2
setuptools : 59.8.0
Cython : None
pytest : None
hypothesis : None
...
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None