Skip to content

Commit 2928cee

Browse files
don't break any other tests, but comment why it may be worth it
1 parent 016c64e commit 2928cee

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pandas/core/frame.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9056,13 +9056,22 @@ def _restore_wide_ints(
90569056
orig_dt_other in [np.int64, np.uint64]
90579057
)
90589058

9059-
if was_promoted and not isna(ser).any():
9059+
if was_promoted:
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, reconcile
9065-
cast_map[col] = find_common_type(dtypes_to_resolve)
9064+
if isna(ser).any():
9065+
# Currently, align upcasts to float64 when NAs are present.
9066+
# Do this so we don't have to modify any tests that expect
9067+
# float dtype when NAs are present. BUT we could consider
9068+
# embracing nullable integer dtype since large integers are
9069+
# still losing information on conversion to float -- it's
9070+
# just not obvious because they aren't cast back to int
9071+
# when NAs are present.
9072+
dtypes_to_resolve.append(np.dtype("float64"))
9073+
target_type = find_common_type(dtypes_to_resolve)
9074+
cast_map[col] = target_type
90669075

90679076
if cast_map:
90689077
combined_df = combined_df.astype(cast_map)

pandas/tests/frame/methods/test_combine_first.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ def test_combine_first_with_nan_multiindex():
490490
"d": [1, 4, np.nan, 2, 5, np.nan, np.nan, 3, np.nan, 6, np.nan],
491491
},
492492
index=mi_expected,
493-
dtype="Int64",
494493
)
495494
tm.assert_frame_equal(res, expected)
496495

@@ -537,7 +536,6 @@ def test_combine_first_duplicates_rows_for_nan_index_values():
537536
index=MultiIndex.from_arrays(
538537
[[1, 2, 3, 4], [np.nan, 5, 6, 7]], names=["a", "b"]
539538
),
540-
dtype="Int64",
541539
)
542540
combined = df1.combine_first(df2)
543541
tm.assert_frame_equal(combined, expected)

0 commit comments

Comments
 (0)