Description
-
I have checked that this issue has not already been reported.
-
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.
Code Sample, a copy-pastable example
d1 = pd.DataFrame([("a",)], columns=["id"], dtype="string")
d2 = pd.DataFrame([("b",)], columns=["id"], dtype="string")
result = d1.merge(d2, on="id", how="outer")
dtype = result.dtypes["id"]
print(dtype) # expected 'string', but is 'object'
Problem description
When doing an outer merge on a column of type string
, the result contains this column with the type object
. This makes it more difficult to use the new string
type.
The problem doesn't occur with the types Int32
, Float32
, boolean
. It seems to be specific to the string
type.
The problem doesn't occur with a left, right or inner-merge.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : 7d32926
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
Version : Darwin Kernel Version 18.7.0: Tue Nov 10 00:07:31 PST 2020; root:xnu-4903.278.51~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.2.2
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 20.2.4
setuptools : 52.0.0.post20210125
Cython : None
pytest : 6.0.1
hypothesis : 5.30.1
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.20.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
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.23
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None