BUG: dangerous inconsistency when setting values on slice of multi-index #34603
Labels
API - Consistency
Internal Consistency of API/Behavior
Bug
Indexing
Related to indexing on series/frames, not to indexes themselves
MultiIndex
Milestone
[ x ] I have checked that this issue has not already been reported.
[ x ] 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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
When assigning to
df
in the last step, I use the index ofdf2
to correctly align the rows of the two DataFrames, i.e., to select the order of elements indf
to assign to. It turns out that this order is ignored in MultiIndex indexing. I believe this is dangerous, becausedf2.values
on the right hand side is the only way to pass the values indf2
todf
as long asdf2
hasn't got the same levels asdf
(cf. #10440). Unsuspecting users who believe that MultiIndex indexing will work as indexing on a normal Index (I haven't found a warning about this in the docs) will most likely miss that their values have been sorted unexpectedly.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 7
machine : AMD64
processor : Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : None.None
pandas : 1.0.3
numpy : 1.18.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3.post20200330
Cython : None
pytest : 5.3.4
hypothesis : None
sphinx : 3.0.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.4
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: