Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample
import pandas as pd
import numpy as np
cols = pd.MultiIndex.from_product([[1], ['a', 'b']])
index = np.arange(2)
data = np.ones((len(index), len(cols)))
df = pd.DataFrame(data=data, index=index, columns=cols)
print(df)
df.loc[:, 1] = df.loc[:, 1]
print(df)
Problem description
When assigning to block of MultiIndex-ed dataframe (I tested with columnar multi-index), data becomes covered with NaNs instead. Same happens when doing right-assign arithmetic operations (*=
, +=
etc.). It is not required for RHS to point to same data storage - any dataframe with corresponding index/columns gives same effect.
Expected Output
1
a b
0 1.0 1.0
1 1.0 1.0
1
a b
0 1.0 1.0
1 1.0 1.0
Output of pd.show_versions()
INSTALLED VERSIONS
commit : f2c8480
python : 3.8.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1251
pandas : 1.2.3
numpy : 1.18.1
pytz : 2020.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.2.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None