Repository: pandas-dev/pandas

Issue:
merge_asof() tolerance cannot be datetime.timedelta 
#### Code Sample
```
import pandas as pd
import numpy as np
from datetime import timedelta

left = pd.DataFrame(
    list(zip([0, 5, 10, 15, 20, 25], [0, 1, 2, 3, 4, 5])),
    columns=["time", "left"],
)
left["time"] = pd.to_timedelta(left["time"], "ms")

right = pd.DataFrame(
    list(zip([0, 3, 9, 12, 15, 18], [0, 1, 2, 3, 4, 5])),
    columns=["time", "right"],
)
right["time"] = pd.to_timedelta(right["time"], "ms")

expected = pd.DataFrame(
    list(
        zip(
            [0, 5, 10, 15, 20, 25],
            [0, 1, 2, 3, 4, 5],
            [0, np.nan, 2, 4, np.nan, np.nan],
        )
    ),
    columns=["time", "left", "right"],
)
expected["time"] = pd.to_timedelta(expected["time"], "ms")
print(expected)

# this throws MergeError: incompatible tolerance <class 'datetime.timedelta'>, must be compat with type dtype('<m8[ns]')
result = pd.merge_asof(left, right, on="time", tolerance=timedelta(microseconds=1000), direction="nearest")

# this works!
# result = pd.merge_asof(left, right, on="time", tolerance=pd.Timedelta("1ms"), direction="nearest")

print(result)
```
#### Problem description
I can use pd.Timedelta as tolerance, but not datetime.timedelta. 

#### Expected Output
No error

#### Output of ``pd.show_versions()``

<details>
INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.3.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.19.0-5-amd64
machine          : x86_64
processor        : 
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 0.25.0+222.gdef01cf7b
numpy            : 1.17.0
pytz             : 2019.2
dateutil         : 2.8.0
pip              : 19.2.2
setuptools       : 41.2.0
Cython           : 0.29.13
pytest           : 5.1.1
hypothesis       : 4.33.1
sphinx           : 1.8.5
blosc            : 1.8.1
feather          : None
xlsxwriter       : 1.1.9
lxml.etree       : 4.4.1
html5lib         : 1.0.1
pymysql          : None
psycopg2         : None
jinja2           : 2.10.1
IPython          : 7.7.0
pandas_datareader: None
bs4              : 4.8.0
bottleneck       : 1.2.1
fastparquet      : 0.3.2
gcsfs            : None
lxml.etree       : 4.4.1
matplotlib       : 3.1.1
numexpr          : 2.7.0
odfpy            : None
openpyxl         : 2.6.3
pandas_gbq       : None
pyarrow          : 0.14.1
pytables         : None
s3fs             : 0.3.3
scipy            : 1.3.1
sqlalchemy       : 1.3.7
tables           : 3.5.2
xarray           : 0.12.3
xlrd             : 1.2.0
xlwt             : 1.3.0
xlsxwriter       : 1.1.9
</details>



Discussion:

Resolving patch:
diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py
--- a/pandas/core/reshape/merge.py
+++ b/pandas/core/reshape/merge.py
@@ -3,6 +3,7 @@
 """
 
 import copy
+import datetime
 from functools import partial
 import string
 import warnings
@@ -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:
@@ -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")
@@ -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


Test patch:
diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py
--- a/pandas/tests/reshape/merge/test_merge_asof.py
+++ b/pandas/tests/reshape/merge/test_merge_asof.py
@@ -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):