Skip to content

merge_asof fails to coerce float types #21559

@crepererum

Description

@crepererum

Code Sample, a copy-pastable example if possible

import numpy as np
import pandas as pd

df1 = pd.DataFrame({'x': pd.Series([1], dtype=np.float64)})
df2 = pd.DataFrame({'x': pd.Series([1], dtype=np.float32)})

df3 = pd.merge(df1, df2, on='x')  # works
df4 = pd.merge_asof(df1, df2, on='x', direction='nearest')  # crashes

Problem description

pd.merge seems to correctly treat float32 and float64 both as floating, but pd.merge_of results in pandas.errors.MergeError: incompatible merge keys [0] float64 and float32, must be the same type.

Expected Output

df3 and df4 should be identical

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.49-moby
machine: x86_64
processor:
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.23.1
pytest: 3.4.0
pip: 10.0.1
setuptools: 39.1.0
Cython: 0.28.2
numpy: 1.14.3
scipy: 1.0.0
pyarrow: 0.9.0
xarray: None
IPython: 5.7.0
sphinx: 1.6.7
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: None
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.0
xlrd: None
xlwt: None
xlsxwriter: 0.8.4
lxml: 3.8.0
bs4: None
html5lib: 1.0.1
sqlalchemy: 1.2.7
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.8.1
s3fs: 0.1
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions