Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge_asof fails to coerce float types #21559

Open
crepererum opened this issue Jun 20, 2018 · 2 comments
Open

merge_asof fails to coerce float types #21559

crepererum opened this issue Jun 20, 2018 · 2 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@crepererum
Copy link
Contributor

crepererum commented Jun 20, 2018

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
@gfyoung gfyoung added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Jun 21, 2018
@gfyoung
Copy link
Member

gfyoung commented Jun 21, 2018

cc @jreback

@gfyoung gfyoung added Dtype Conversions Unexpected or buggy dtype conversions Numeric Operations Arithmetic, Comparison, and Logical operations labels Jun 21, 2018
@mroeschke mroeschke added Bug and removed Numeric Operations Arithmetic, Comparison, and Logical operations labels Jun 20, 2021
@fcenzato
Copy link

Are there any updates on this? I found the same issue even when merging on pd.Int64Dtype() and np.int64

import pandas as pd

df1 = pd.DataFrame({"by": [0, 1], "key": [1, 5]})
df2 = pd.DataFrame({"by": [1, 2], "key": [2, 6]})

df2["by"] = df2["by"].astype(pd.Int32Dtype())

df = pd.merge_asof(df1, df2, by="by", on="key")  # crashes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

4 participants