-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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: Columns resulting from joining multiIndex dataFrame are incorrect in python 3.12.1 #57500
Comments
@yuji38kwmt - can you pls provide folder path for this issue. |
The bug does not depend on folder path. For example, you can reproduce the bug in IPython.
|
I don't know what causes the problem, but concat is a little workaround: df3 = pd.concat([df1, df2], axis=1) #there is join options too |
The following code behaved expectedly.
Apparently the problem occurs when the key with label 1 is an empty string. |
Confirmed that this still exists on 2.2.1, but not yet on main. Further investigations and PRs to fix are welcome! |
I did a litter investigated the bug. The following code creates a Trial1
Trial2
|
Also encountering this issue. I'll see if I can come up with a bug fix. It seems related to Python 3.12 changes, not Pandas changes. I'm failing all of my tests for py3.12 against Pandas 1.5, 2.0, 2.1, and 2.2. |
As @yuji38kwmt noted, the error is due to the way in which Pandas handles the Also note that I'll be submitting a PR. I think it should be as easy as switching the position of the conditions in |
(#58043) * Reorder slice and hashable in __getitem__ * Add unit test * Fix test and formatting * Update whatsnew * Restore original flow ordering * Move whatsnew entry to 3.0.0 * Move whatsnew entry to Indexing * Update doc/source/whatsnew/v3.0.0.rst --------- Co-authored-by: Matthew Roeschke <[email protected]>
…das-dev#57500 (pandas-dev#58043) * Reorder slice and hashable in __getitem__ * Add unit test * Fix test and formatting * Update whatsnew * Restore original flow ordering * Move whatsnew entry to 3.0.0 * Move whatsnew entry to Indexing * Update doc/source/whatsnew/v3.0.0.rst --------- Co-authored-by: Matthew Roeschke <[email protected]>
Thank you! Got it. |
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
In Python 3.12.1, the
print(f"{df3=}")
statement output the following string.And
df3[("A","")]
occursKeyError
.But in python 3.11.7,
df3[("A","")]
does not occurKeyError
.Expected Behavior
The
print(f"{df3=}")
statement output the following string.Installed Versions
pd.show_versions()
INSTALLED VERSIONS
commit : a671b5a
python : 3.12.1.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.133.1-microsoft-standard-WSL2
Version : #1 SMP Thu Oct 5 21:02:42 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : C.UTF-8
pandas : 2.1.4
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : None
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.1.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.21.0
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: