Skip to content

Fix 18068: Updates merge_asof error, now outputs datatypes #18082

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 5 commits into from
Nov 3, 2017
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.21.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Sparse
Reshaping
^^^^^^^^^

-
- Error message in ``pd.merge_asof()`` for key datatype mismatch now includes datatype of left and right key (:issue:`18068`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use :func:`merge_asof` so we get the link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback Is there a documentation for syntax to be used for release notes? Also, how can I view rendered version of it?

Making the required change. Also, will add test for the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no this is fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation is look at similar notes!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you would have to build the docs to render it

-
-

Expand Down
8 changes: 5 additions & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,10 +1253,12 @@ def _get_merge_keys(self):
join_names) = super(_AsOfMerge, self)._get_merge_keys()

# validate index types are the same
for lk, rk in zip(left_join_keys, right_join_keys):
for i, (lk, rk) in enumerate(zip(left_join_keys, right_join_keys)):
if not is_dtype_equal(lk.dtype, rk.dtype):
raise MergeError("incompatible merge keys, "
"must be the same type")
raise MergeError("incompatible merge keys [{i}] {lkdtype} and "
"{rkdtype}, must be the same type"
.format(i=i, lkdtype=lk.dtype,
rkdtype=rk.dtype))

# validate tolerance; must be a Timedelta if we have a DTI
if self.tolerance is not None:
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/reshape/test_merge_asof.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,3 +973,15 @@ def test_on_float_by_int(self):
columns=['symbol', 'exch', 'price', 'mpv'])

assert_frame_equal(result, expected)

def test_merge_datatype_error(self):
""" Tests merge datatype mismatch error """
msg = 'merge keys \[0\] object and int64, must be the same type'

left = pd.DataFrame({'left_val': [1, 5, 10],
'a': ['a', 'b', 'c']})
right = pd.DataFrame({'right_val': [1, 2, 3, 6, 7],
'a': [1, 2, 3, 6, 7]})

with tm.assert_raises_regex(MergeError, msg):
merge_asof(left, right, on='a')