Skip to content
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
6 changes: 5 additions & 1 deletion pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions pandas/tests/dtypes/cast/test_find_common_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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

Expand Down
Loading