Skip to content

Raise MergeError on mismatched signed/unsigned int merge keys #61694

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,16 @@ def _maybe_coerce_merge_keys(self) -> None:
lk = extract_array(lk, extract_numpy=True)
rk = extract_array(rk, extract_numpy=True)

# Explicitly disallow merging int64 and uint64 (or vice versa)
if (lk.dtype == np.dtype("int64") and rk.dtype == np.dtype("uint64")) or (
lk.dtype == np.dtype("uint64") and rk.dtype == np.dtype("int64")
):
raise ValueError(
f"You are trying to merge on int64 and uint64 columns for key '{name}'. "
"This is not allowed as it can lead to incorrect results. "
"Please cast both columns to the same signedness before merging."
)

lk_is_cat = isinstance(lk.dtype, CategoricalDtype)
rk_is_cat = isinstance(rk.dtype, CategoricalDtype)
lk_is_object_or_string = is_object_dtype(lk.dtype) or is_string_dtype(
Expand Down
Loading