Skip to content

Commit bf69fad

Browse files
create new test for issue
1 parent f80917d commit bf69fad

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pandas/core/frame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9052,16 +9052,16 @@ def _restore_wide_ints(
90529052
orig_dt_self = self_original.dtypes.get(col)
90539053
orig_dt_other = other_original.dtypes.get(col)
90549054

9055-
is_at_risk = (orig_dt_self in [np.int64, np.uint64]) or (
9055+
was_promoted = (orig_dt_self in [np.int64, np.uint64]) or (
90569056
orig_dt_other in [np.int64, np.uint64]
90579057
)
90589058

9059-
if is_at_risk and not isna(ser).any():
9059+
if was_promoted and not isna(ser).any():
90609060
dtypes_to_resolve = [
90619061
dt for dt in (orig_dt_self, orig_dt_other) if dt is not None
90629062
]
90639063
if dtypes_to_resolve:
9064-
# if we had different dtypes, possibly promote
9064+
# if we had different dtypes, reconcile
90659065
cast_map[col] = find_common_type(dtypes_to_resolve)
90669066

90679067
if cast_map:

pandas/tests/frame/methods/test_combine_first.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ def test_combine_first_string_dtype_only_na(self, nullable_string_dtype):
398398
).set_index(["a", "b"])
399399
tm.assert_frame_equal(result, expected)
400400

401+
@pytest.mark.parametrize(
402+
"wide_val, dtype, EAdtype",
403+
(
404+
(1666880195890293744, "uint64", "UInt64"),
405+
(-1666880195890293744, "int64", "Int64"),
406+
),
407+
)
408+
def test_combine_first_preserve_precision(self, wide_val, dtype, EAdtype):
409+
# GH#60128
410+
df1 = DataFrame({"A": [wide_val, 5]}, dtype=dtype)
411+
df2 = DataFrame({"A": [6, 7, wide_val]}, dtype=dtype)
412+
result = df1.combine_first(df2)
413+
expected = DataFrame({"A": [wide_val, 5, wide_val]}, dtype=dtype)
414+
tm.assert_frame_equal(result, expected)
415+
401416

402417
@pytest.mark.parametrize(
403418
"scalar1, scalar2",

0 commit comments

Comments
 (0)