BUG: Merge with EA and MultiIndex (original) (raw)

Reproducible Example

import pandas as pd

df1 = pd.DataFrame(data={("lvl0","lvl1-a"): ["1","2","3"], ("lvl0","lvl1-b"): ["4","5","6"]}, dtype=str)

df2 = pd.DataFrame(data={("lvl0","lvl1-a"): ["1","2","3"], ("lvl0","lvl1-c"): ["7","8","9"]}, dtype=pd.StringDtype())

result = pd.merge(left=df1, right=df2, on=[("lvl0","lvl1-a")])

Issue Description

I am trying to make a merge between two data frames with a MultiIndex for the columns. The first data frame has an object data type (str in my example) and the second an extension array data type (pd.StringDtype() in my example). In this case, in an internal method, an assign method is used but unfortunately, the name of the column is not a string but a tuple...

Expected Behavior

I would have expected the merge to happen as it is with two str dtype data frames or two pd.StirngDtype() dtype data frames.

    lvl0              
  lvl1-a lvl1-b lvl1-c
0      1      4      7
1      2      5      8
2      3      6      9

Installed Versions

Details

INSTALLED VERSIONS

commit : 73c6825
python : 3.9.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.0-8-amd64
Version : #1 SMP Debian 5.10.46-4 (2021-08-03)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : fr_FR.UTF-8
LOCALE : fr_FR.UTF-8
pandas : 1.3.3
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 57.4.0
Cython : 0.29.24
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.4.25
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None