Skip to content

ENH: improve 'incompatible tolerance' error message in merge_asof #17260

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 2 commits into from
Nov 10, 2017
Merged
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
12 changes: 7 additions & 5 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _groupby_and_merge(by, on, left, right, _merge_pieces,
try:
if k in merged:
merged[k] = key
except:
except KeyError:
pass

pieces.append(merged)
Expand Down Expand Up @@ -1268,8 +1268,10 @@ def _get_merge_keys(self):
else:
lt = left_join_keys[-1]

msg = "incompatible tolerance, must be compat " \
"with type {lt}".format(lt=type(lt))
msg = ("incompatible tolerance {tolerance}, must be compat "
"with type {lkdtype}".format(
tolerance=type(self.tolerance),
lkdtype=lt.dtype))

if is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt):
if not isinstance(self.tolerance, Timedelta):
Expand Down Expand Up @@ -1505,12 +1507,12 @@ def _sort_labels(uniques, left, right):
# tuplesafe
uniques = Index(uniques).values

l = len(left)
llength = len(left)
labels = np.concatenate([left, right])

_, new_labels = sorting.safe_sort(uniques, labels, na_sentinel=-1)
new_labels = _ensure_int64(new_labels)
new_left, new_right = new_labels[:l], new_labels[l:]
new_left, new_right = new_labels[:llength], new_labels[llength:]

return new_left, new_right

Expand Down