Skip to content

BUG: Merge duplicates and validation failure when columns have type int64 and uint64 #61688

Open
@mratkin0

Description

@mratkin0

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

da = pd.DataFrame()
db = pd.DataFrame()
da["t"] = np.array([1721088000012322083, 1721088047408560273, 1721088047408560451], dtype=np.int64)   # Note different types here
db["t"] = np.array([1721088000012322083, 1721088047408560273, 1721088047408560451], dtype=np.uint64)  # Note different types here
da["i"] = 1
db["i"] = 1
da["p"] = [3, 6, 2]
db["q"] = [1, 2, 2]

print(pd.merge(da, db, on=["i", "t"], how="left", validate="1:1"))
print(pd.merge(da, db, on=["t"], how="left", validate="1:1"))

Issue Description

Running the example produces some very strange results:
The first print returns:
---------------t-------------------i-p-q
0 1721088000012322083 1 3 1
1 1721088047408560273 1 6 2
2 1721088047408560273 1 6 2
3 1721088047408560451 1 2 2
4 1721088047408560451 1 2 2

Firstly I wouldn't expect there to be a collision of join keys despite an implicit cast between uint64 and int64. Even allowing for this, the collision doesn't trigger the validate='1:1' check.

Stranger still it seems if you drop the first trivial join key, then the merge is clean!
-------------t------------------i_x-p-i_y-q
0 1721088000012322083 1 3 1 1
1 1721088047408560273 1 6 1 2
2 1721088047408560451 1 2 1 2

Expected Behavior

I would expect the output to be:
-------------t------------------i_x-p-i_y-q
0 1721088000012322083 1 3 1 1
1 1721088047408560273 1 6 1 2
2 1721088047408560451 1 2 1 2

in both cases or for validate to throw in the first case.

Installed Versions

INSTALLED VERSIONS

commit : 2cc3762
python : 3.12.11
python-bits : 64
OS : Linux
OS-release : 6.1.0-37-amd64
Version : #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22)
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : C.UTF-8

pandas : 2.3.0
numpy : 2.2.6
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : None
sphinx : None
IPython : 9.3.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.4
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2025.5.1
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.3
numba : 0.61.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 20.0.0
pyreadstat : None
pytest : 8.3.5
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : 0.23.0
tzdata : 2025.2
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BugNeeds TriageIssue that has not been reviewed by a pandas team member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions