Skip to content

Commit e4aa9b6

Browse files
RITAMIT2023RITAMIT2023
authored andcommitted
Raise MergeError on mismatched signed/unsigned int merge keys
1 parent 1da0d02 commit e4aa9b6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/core/reshape/merge.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,17 @@ def _maybe_coerce_merge_keys(self) -> None:
16701670
lk = extract_array(lk, extract_numpy=True)
16711671
rk = extract_array(rk, extract_numpy=True)
16721672

1673+
# Explicitly disallow merging int64 and uint64 (or vice versa)
1674+
if (
1675+
(lk.dtype == np.dtype("int64") and rk.dtype == np.dtype("uint64"))
1676+
or (lk.dtype == np.dtype("uint64") and rk.dtype == np.dtype("int64"))
1677+
):
1678+
raise ValueError(
1679+
f"You are trying to merge on int64 and uint64 columns for key '{name}'. "
1680+
"This is not allowed as it can lead to incorrect results. "
1681+
"Please cast both columns to the same signedness before merging."
1682+
)
1683+
16731684
lk_is_cat = isinstance(lk.dtype, CategoricalDtype)
16741685
rk_is_cat = isinstance(rk.dtype, CategoricalDtype)
16751686
lk_is_object_or_string = is_object_dtype(lk.dtype) or is_string_dtype(

0 commit comments

Comments
 (0)