BUG: Columns resulting from joining multiIndex dataFrame are incorrect in python 3.12.1 · Issue #57500 · pandas-dev/pandas (original) (raw)
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
import pandas
df1=pandas.DataFrame({("A",""):[1,2,3]},index=["x","y","z"]) df2=pandas.DataFrame({("B",""):[11,12,13]},index=["x","y","z"])
df3 = df1.join(df2)
print(f"{df3.columns=}")
Issue Description
In Python 3.12.1, the print(f"{df3=}")
statement output the following string.
df3.columns=Index([slice(None, None, None), slice(None, None, None)], dtype='object')
And df3[("A","")]
occurs KeyError
.
But in python 3.11.7, df3[("A","")]
does not occur KeyError
.
Expected Behavior
The print(f"{df3=}")
statement output the following string.
df3.columns=MultiIndex([('A', ''),('B', '')])
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