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 · Fixed by #22982
Closed

merge_asof doesn't allow float tolerance for float merges #22981

svenharris opened this issue Oct 3, 2018 · 2 comments · Fixed by #22982
Labels
Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@svenharris
Copy link
Contributor

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 mentioned this issue Oct 3, 2018
4 tasks
@mroeschke mroeschke added Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Oct 3, 2018
@jreback jreback added this to the 0.24.0 milestone Oct 4, 2018
@ProxyCausal
Copy link

ProxyCausal commented Dec 22, 2018

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

@svenharris
Copy link
Contributor Author

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
Labels
Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants