-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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: loc assignment with a numpy array fails when MultiIndex columns are not sorted #38601
Comments
Thanks @mosalx for the report
first bad commit: [33f67d9] BUG: iloc.setitem with duplicate columns (#32477) cc @jbrockmendel |
take |
This seems to have reemerged as a problem. I get the same exception in Pandas 1.4.0, but rolling back to 1.2.1 fixes the issue. |
can't reproduce. Code sample works in 1.4.0 for me. can you open a new issue with a reproducible minimum example and output of show versions. A closed issue is less likely to get so much attention. |
You're right. I was doing something like:
Pandas 1.2.1 appears to ignore the fact that column |
[ 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
Assigning a numpy array to a subset of columns using 'loc' behaves inconsistently with multi-level columns. The behavior depends on the lexsort state of the column index. If the columns are not lexsorted, the assignment fails as shown in the code example. Otherwise the assignment succeeds. This issue affects pandas 1.1.5 and 1.1.0 but not 1.0.5.
Expected Output
'loc' assignment is expected to succeed regardless of the columns' lexsort state
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : b5958ee
python : 3.8.5.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.1252
pandas : 1.1.5
numpy : 1.19.2
pytz : 2020.4
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.0.0.post20201207
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.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
Traceback
The text was updated successfully, but these errors were encountered: