Skip to content

DataFrame.merge with empty frame and Int64 column gives object dtype #25183

Closed
@josham

Description

@josham

Code Sample, a copy-pastable example if possible

x = pd.DataFrame({
    'date': pd.Series([pd.Timestamp('2018-01-01')]),
    'value': pd.Series([1], dtype='Int64')
})
y = x[:0]
z = x.merge(y, on='date', how='left')

# z
        date  value_x value_y
0 2018-01-01        1     NaN

# z.dtypes

date       datetime64[ns]
value_x             Int64
value_y            object
dtype: object

Problem descriptioy

The dtype of the value_y column should be Int64.

Expected Output

date       datetime64[ns]
value_x             Int64
value_y             Int64
dtype: object

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-43-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C.UTF-8
LANG: C.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.24.1
pytest: 4.1.1
pip: 18.1
setuptools: 40.6.3
Cython: 0.29.2
numpy: 1.15.4
scipy: None
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: 1.8.2
patsy: None
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.3.0
bs4: None
html5lib: None
sqlalchemy: 1.2.16
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversionsExtensionArrayExtending pandas with custom dtypes or arrays.ReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions