Skip to content

Commit 06e6a27

Browse files
committed
BUG pandas-devGH-35558 merge_asof error for tolerance with left and right index
1 parent a9cb64a commit 06e6a27

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

doc/source/whatsnew/v1.1.1.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717

1818
- Fixed regression where :meth:`DataFrame.to_numpy` would raise a ``RuntimeError`` for mixed dtypes when converting to ``str`` (:issue:`35455`)
19-
- Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`).
19+
- Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`)
2020
- Fixed regression in :class:`pandas.core.groupby.RollingGroupby` where column selection was ignored (:issue:`35486`)
2121
- Fixed regression in :meth:`DataFrame.shift` with ``axis=1`` and heterogeneous dtypes (:issue:`35488`)
2222
- Fixed regression in ``.groupby(..).rolling(..)`` where a segfault would occur with ``center=True`` and an odd number of values (:issue:`35552`)
23+
- Fixed regression where :meth:`DataFrame.merge_asof` would raise a ``UnboundLocalError`` when ``left_index`` , ``right_index`` and ``tolerance`` were set (:issue:`35558`)
2324

2425
.. ---------------------------------------------------------------------------
2526

pandas/core/reshape/merge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ def _get_merge_keys(self):
16671667

16681668
msg = (
16691669
f"incompatible tolerance {self.tolerance}, must be compat "
1670-
f"with type {repr(lk.dtype)}"
1670+
f"with type {repr(lt.dtype)}"
16711671
)
16721672

16731673
if needs_i8_conversion(lt):

pandas/tests/reshape/merge/test_merge_asof.py

+15
Original file line numberDiff line numberDiff line change
@@ -1339,3 +1339,18 @@ def test_merge_index_column_tz(self):
13391339
index=pd.Index([0, 1, 2, 3, 4]),
13401340
)
13411341
tm.assert_frame_equal(result, expected)
1342+
1343+
def test_left_index_right_index_tolerance(self):
1344+
expected = self.asof.set_index("time")
1345+
trades = self.trades.set_index("time")
1346+
quotes = self.quotes.set_index("time")
1347+
1348+
result = merge_asof(
1349+
trades,
1350+
quotes,
1351+
left_index=True,
1352+
right_index=True,
1353+
by="ticker",
1354+
tolerance=Timedelta("1day"),
1355+
)
1356+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)