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 doesn't allow float tolerance for float merges #22981

Closed
svenharris opened this issue Oct 3, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@svenharris
Copy link
Contributor

commented Oct 3, 2018

The merge_asof function allows you to merge on float values but doesn't allow tolerance value when performing this merge, unlike for integer and datetime merges. I'm currently working on a pull request to fix this by removing the error being thrown for non-integer numerical tolerances.

left = pd.DataFrame({'a': [1.1, 3.5, 10.9],
                     'left_val': ['a', 'b', 'c']})

right = pd.DataFrame({'a': [1.0, 2.5, 3.3, 7.5, 11.5],
                      'right_val': [1.0, 2.5, 3.3, 7.5, 11.5]})

expected = pd.DataFrame({'a': [1.1, 3.5, 10.9],
                         'left_val': ['a', 'b', 'c'],
                         'right_val': [1, 3.3, np.nan]})

result = pd.merge_asof(left, right, on='a', direction='nearest',
                       tolerance=0.5)

MergeError: key must be integer or timestamp

Expected output:

     a left_val  right_val
0   1.1        a        1.0
1   3.5        b        3.3
2  10.9        c        NaN

@svenharris svenharris referenced this issue Oct 3, 2018

Merged

Merge asof float fix #22982

0 of 4 tasks complete

@jreback jreback added this to the 0.24.0 milestone Oct 4, 2018

@ProxyCausal

This comment has been minimized.

Copy link

commented Dec 22, 2018

this functionality will be officially added in the upcoming release 0.24?

@svenharris

This comment has been minimized.

Copy link
Contributor Author

commented Dec 22, 2018

You might find my answer to this stack overflow question helpful for the time being

https://stackoverflow.com/questions/52503816/pandas-merge-asof-error-when-using-float-as-key/52503878#52503878

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.