Skip to content

BUG: GH-35558 merge_asof tolerance error #35654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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.1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Fixed regressions
- Fixed regression in :meth:`DataFrame.shift` with ``axis=1`` and heterogeneous dtypes (:issue:`35488`)
- Fixed regression in ``.groupby(..).rolling(..)`` where a segfault would occur with ``center=True`` and an odd number of values (:issue:`35552`)
- Fixed regression in :meth:`DataFrame.apply` where functions that altered the input in-place only operated on a single row (:issue:`35462`)
- Fixed regression where :meth:`DataFrame.merge_asof` would raise a ``UnboundLocalError`` when ``left_index`` , ``right_index`` and ``tolerance`` were set (:issue:`35558`)
- Fixed regression in ``.groupby(..).rolling(..)`` where a custom ``BaseIndexer`` would be ignored (:issue:`35557`)

.. ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ def _get_merge_keys(self):

msg = (
f"incompatible tolerance {self.tolerance}, must be compat "
f"with type {repr(lk.dtype)}"
f"with type {repr(lt.dtype)}"
)

if needs_i8_conversion(lt):
Expand Down
22 changes: 22 additions & 0 deletions pandas/tests/reshape/merge/test_merge_asof.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,3 +1339,25 @@ def test_merge_index_column_tz(self):
index=pd.Index([0, 1, 2, 3, 4]),
)
tm.assert_frame_equal(result, expected)

def test_left_index_right_index_tolerance(self):
# https://github.com/pandas-dev/pandas/issues/35558
dr1 = pd.date_range(
start="1/1/2020", end="1/20/2020", freq="2D"
) + pd.Timedelta(seconds=0.4)
dr2 = pd.date_range(start="1/1/2020", end="2/1/2020")

df1 = pd.DataFrame({"val1": "foo"}, index=pd.DatetimeIndex(dr1))
df2 = pd.DataFrame({"val2": "bar"}, index=pd.DatetimeIndex(dr2))

expected = pd.DataFrame(
{"val1": "foo", "val2": "bar"}, index=pd.DatetimeIndex(dr1)
)
result = pd.merge_asof(
df1,
df2,
left_index=True,
right_index=True,
tolerance=pd.Timedelta(seconds=0.5),
)
tm.assert_frame_equal(result, expected)