Skip to content

pd.merge_asof() matches out of tolerance when allow_exact_matches=False #13695

Closed
@chrisaycock

Description

@chrisaycock

Using these DataFrames for this example:

df1 = pd.DataFrame({'time':pd.to_datetime(['2016-07-15 13:30:00.030']), 'username':['bob']})
df2 = pd.DataFrame({'time':pd.to_datetime(['2016-07-15 13:30:00.000', '2016-07-15 13:30:00.030']), 'version':[1, 2]})

I can perform the pd.merge_asof() as expected:

In [153]: df1
Out[153]:
                     time username
0 2016-07-15 13:30:00.030      bob

In [154]: df2
Out[154]:
                     time  version
0 2016-07-15 13:30:00.000        1
1 2016-07-15 13:30:00.030        2

In [155]: pd.merge_asof(df1, df2, on='time')
Out[155]:
                     time username  version
0 2016-07-15 13:30:00.030      bob        2

If I disable the exact matches, then I get the prior entry as expected:

In [156]: pd.merge_asof(df1, df2, on='time', allow_exact_matches=False)
Out[156]:
                     time username  version
0 2016-07-15 13:30:00.030      bob        1

But the tolerance isn't respected when I disable the exact matches!

In [157]: pd.merge_asof(df1, df2, on='time', allow_exact_matches=False, tolerance=pd.Timedelta('10ms'))
Out[157]:
                     time username  version
0 2016-07-15 13:30:00.030      bob        1

I expect to get a null here.

This is pandas version 0.18.0+408.gd8f3d73.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions