Skip to content

Commit 160a4e3

Browse files
committed
generalized cast and adjusted test cases
1 parent 7edf076 commit 160a4e3

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pandas/core/dtypes/cast.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,11 @@ def np_find_common_type(*dtypes: np.dtype) -> np.dtype:
14101410
"""
14111411
try:
14121412
common_dtype = np.result_type(*dtypes)
1413-
if common_dtype.kind in "mMSU" or common_dtype not in dtypes:
1413+
# GH 59609
1414+
# Float point precision error when converting int64 and uint64
1415+
if common_dtype.kind in "mMSU" or common_dtype.kind not in [
1416+
dtype.kind for dtype in dtypes
1417+
]:
14141418
# NumPy promotion currently (1.25) misbehaves for for times and strings,
14151419
# so fall back to object (find_common_dtype did unless there
14161420
# was only one dtype)

pandas/tests/dtypes/cast/test_find_common_type.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
((np.float16, np.float32), np.float32),
3232
((np.float16, np.int16), np.float32),
3333
((np.float32, np.int16), np.float32),
34-
((np.uint64, np.int64), np.float64),
3534
((np.int16, np.float64), np.float64),
3635
((np.float16, np.int64), np.float64),
3736
# Into others.
3837
((np.complex128, np.int32), np.complex128),
3938
((object, np.float32), object),
4039
((object, np.int16), object),
40+
# GH 59609
41+
# Float point precision error when converting int64 and uint64
42+
((np.uint64, np.int64), object),
4143
# Bool with int.
4244
((np.dtype("bool"), np.int64), object),
4345
((np.dtype("bool"), np.int32), object),
@@ -156,8 +158,17 @@ def test_interval_dtype(left, right):
156158
# i.e. numeric
157159
if right.subtype.kind in ["i", "u", "f"]:
158160
# both numeric -> common numeric subtype
159-
expected = IntervalDtype(np.float64, "right")
160-
assert result == expected
161+
if (
162+
left.subtype.kind == "i"
163+
and right.subtype.kind == "u"
164+
or left.subtype.kind == "u"
165+
and right.subtype.kind == "i"
166+
):
167+
assert result == object
168+
else:
169+
expected = IntervalDtype(np.float64, "right")
170+
assert result == expected
171+
161172
else:
162173
assert result == object
163174

0 commit comments

Comments
 (0)