Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ Reshaping

- Bug in :meth:`DataFrame.apply` that caused incorrect output with empty :class:`DataFrame` (:issue:`28202`, :issue:`21959`)
- Bug in :meth:`DataFrame.stack` not handling non-unique indexes correctly when creating MultiIndex (:issue: `28301`)
- Bug :func:`merge_asof` could not use :class:`datetime.timedelta` for ``tolerance`` kwarg (:issue:`28098`)

Sparse
^^^^^^
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import copy
import datetime
from functools import partial
import string
import warnings
Expand Down Expand Up @@ -1619,7 +1620,7 @@ def _get_merge_keys(self):
)
raise MergeError(msg)

# validate tolerance; must be a Timedelta if we have a DTI
# validate tolerance; datetime.timedelta or Timedelta if we have a DTI
if self.tolerance is not None:

if self.left_index:
Expand All @@ -1635,7 +1636,7 @@ def _get_merge_keys(self):
)

if is_datetimelike(lt):
if not isinstance(self.tolerance, Timedelta):
if not isinstance(self.tolerance, datetime.timedelta):
raise MergeError(msg)
if self.tolerance < Timedelta(0):
raise MergeError("tolerance must be positive")
Expand Down Expand Up @@ -1705,6 +1706,7 @@ def flip(xs):
left_values = left_values.view("i8")
right_values = right_values.view("i8")
if tolerance is not None:
tolerance = Timedelta(tolerance)
tolerance = tolerance.value

# a "by" parameter requires special handling
Expand Down
8 changes: 1 addition & 7 deletions pandas/tests/reshape/merge/test_merge_asof.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,7 @@ def test_non_sorted(self):

@pytest.mark.parametrize(
"tolerance",
[
Timedelta("1day"),
pytest.param(
datetime.timedelta(days=1),
marks=pytest.mark.xfail(reason="not implemented", strict=True),
),
],
[Timedelta("1day"), datetime.timedelta(days=1)],
ids=["pd.Timedelta", "datetime.timedelta"],
)
def test_tolerance(self, tolerance):
Expand Down