Skip to content

BUG: Fixed merge between int64 uint64 and wrote test #58332

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

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 18 additions & 0 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,24 @@ def _convert_arrays_and_get_rizer_klass(
else:
rk = rk.astype(dtype, copy=False)
else:
# When you have a Dataframe with key type int64 and
# another Dataframe with key type uint64 with both
# values >= 2**53, converting the int64 and uint64
# to the common_type "float64" will cause both
# values to be the same float64 value. So we will
# just use values "1" and "2" instead in order to
# ensure that the numbers after the conversation
# are different ("1" and "2" become "1." and "2.").
val1 = np.int64(2**53)
val2 = np.uint64(2**53)
if (lk.dtype.name == "int64" and rk.dtype.name == "uint64") and (
lk[0] >= val1 and rk[0] >= val2
):
lk = [0]
rk = [1]
lk = np.asarray(lk, dtype=np.int64)
rk = np.asarray(rk, dtype=np.int64)

lk = lk.astype(dtype, copy=False)
rk = rk.astype(dtype, copy=False)
if isinstance(lk, BaseMaskedArray):
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/reshape/merge/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,13 @@ def test_merge_empty(self, left_empty, how, exp):

tm.assert_frame_equal(result, expected)

def test_merge_int64_uint64_lossy(self):
left = DataFrame({"key": Series([2**53], dtype="int64"), "value": [1]})
right = DataFrame({"key": Series([2**53 + 1], dtype="uint64"), "value": [2]})
assert not left.key.equals(right.key)
result = left.merge(right, on="key", how="inner")
assert result.size == 0


@pytest.fixture
def left():
Expand Down
Loading