Repository: pandas-dev/pandas

Issue:
Merge_asof() Requires specific int type, not reflected in error or documentation
#### Code Sample, a copy-pastable example if possible

```python
import pandas as pd

left = pd.DataFrame({'ts_int': [0, 100, 200], 'left_val': [1, 2, 3]})
right = pd.DataFrame({'ts_int': [50, 150, 250], 'right_val': [1, 2, 3]})
left['ts_int'] = left['ts_int'].astype(int)
right['ts_int'] = right['ts_int'].astype(int)
pd.merge_asof(left, right, on='ts_int', tolerance=100)

> pandas.errors.MergeError: key must be integer, timestamp or float

print(left['ts_int'].dtype)
>>> int32
print(right['ts_int'].dtype)
>>> int32
```
#### Problem description

merge_asof() throws the MergeError `key must be integer, timestamp or float` even when the data used to merge on is a valid integer type.

This happens with all types of int with the exception of int64, as a result of the check performed when a tolerance is passed _(pandas/core/reshape/merge.py:1641)_. This check uses the `is_int64_dtype(lt)`, which will ofcourse return `False` for every type of int that isn't `int64`. This requirement of the `on` key being int64 is however not documented in the docs, nor is it reflected from the raised error.

#### Expected Output

The expected output can go either of two ways. If it should be possible to perform the merge on every integer type, the expected output would be:
```
   ts_int  left_val  right_val
0       0         1        NaN
1     100         2        1.0
2     200         3        2.0
```

If it shouldn't be possible, I'd expect the returned MergeError and/or the docs to reflect that the integer type that should be used as key to merge on has to be of int64 type.

#### Output of ``pd.show_versions()``

<details>
INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.4.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
machine          : AMD64
processor        : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : None.None

pandas           : 0.25.1
numpy            : 1.17.2
pytz             : 2019.2
dateutil         : 2.8.0
pip              : 19.2.3
setuptools       : 41.2.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : 3.1.1
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : 1.3.1
sqlalchemy       : None
tables           : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None
</details>



Discussion:
I think this is because `.astype(int)` will convert your data to your OS's (Windows) platform int which is 32 bit. `is_int64_dtype` should just be replaced with `is_integer_dtype`. Care to submit a PR?
@mroeschke I can pick this up if @jjlkant doesn't want to.
Go for it @amcnulty93 

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
@@ -28,7 +28,6 @@
     is_dtype_equal,
     is_extension_array_dtype,
     is_float_dtype,
-    is_int64_dtype,
     is_integer,
     is_integer_dtype,
     is_list_like,
@@ -1641,7 +1640,7 @@ def _get_merge_keys(self):
                 if self.tolerance < Timedelta(0):
                     raise MergeError("tolerance must be positive")
 
-            elif is_int64_dtype(lt):
+            elif is_integer_dtype(lt):
                 if not is_integer(self.tolerance):
                     raise MergeError(msg)
                 if self.tolerance < 0:


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
@@ -1287,3 +1287,19 @@ def test_timedelta_tolerance_nearest(self):
         )
 
         assert_frame_equal(result, expected)
+
+    def test_int_type_tolerance(self, any_int_dtype):
+        # GH #28870
+
+        left = pd.DataFrame({"a": [0, 10, 20], "left_val": [1, 2, 3]})
+        right = pd.DataFrame({"a": [5, 15, 25], "right_val": [1, 2, 3]})
+        left["a"] = left["a"].astype(any_int_dtype)
+        right["a"] = right["a"].astype(any_int_dtype)
+
+        expected = pd.DataFrame(
+            {"a": [0, 10, 20], "left_val": [1, 2, 3], "right_val": [np.nan, 1.0, 2.0]}
+        )
+        expected["a"] = expected["a"].astype(any_int_dtype)
+
+        result = pd.merge_asof(left, right, on="a", tolerance=10)
+        assert_frame_equal(result, expected)