diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 6ba07b1761557..0bb8d73bdc508 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1410,7 +1410,11 @@ def np_find_common_type(*dtypes: np.dtype) -> np.dtype: """ try: common_dtype = np.result_type(*dtypes) - if common_dtype.kind in "mMSU": + # GH 59609 + # Float point precision error when converting int64 and uint64 + if common_dtype.kind in "mMSU" or common_dtype.kind not in [ + dtype.kind for dtype in dtypes + ]: # NumPy promotion currently (1.25) misbehaves for for times and strings, # so fall back to object (find_common_dtype did unless there # was only one dtype) diff --git a/pandas/tests/dtypes/cast/test_find_common_type.py b/pandas/tests/dtypes/cast/test_find_common_type.py index 83ef7382fbe8a..47e37fef52201 100644 --- a/pandas/tests/dtypes/cast/test_find_common_type.py +++ b/pandas/tests/dtypes/cast/test_find_common_type.py @@ -31,13 +31,15 @@ ((np.float16, np.float32), np.float32), ((np.float16, np.int16), np.float32), ((np.float32, np.int16), np.float32), - ((np.uint64, np.int64), np.float64), ((np.int16, np.float64), np.float64), ((np.float16, np.int64), np.float64), # Into others. ((np.complex128, np.int32), np.complex128), ((object, np.float32), object), ((object, np.int16), object), + # GH 59609 + # Float point precision error when converting int64 and uint64 + ((np.uint64, np.int64), object), # Bool with int. ((np.dtype("bool"), np.int64), object), ((np.dtype("bool"), np.int32), object), @@ -156,8 +158,12 @@ def test_interval_dtype(left, right): # i.e. numeric if right.subtype.kind in ["i", "u", "f"]: # both numeric -> common numeric subtype - expected = IntervalDtype(np.float64, "right") - assert result == expected + if (left.subtype.kind, right.subtype.kind) in [("i", "u"), ("u", "i")]: + assert result == object + else: + expected = IntervalDtype(np.float64, "right") + assert result == expected + else: assert result == object