Skip to content

Commit 9376815

Browse files
authored
TST: df.combine_first duplicates rows for nan index values (#39881) (#43066)
1 parent 2bdb535 commit 9376815

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pandas/tests/frame/methods/test_combine_first.py

+25
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,28 @@ def test_combine_preserve_dtypes():
492492
)
493493
combined = df1.combine_first(df2)
494494
tm.assert_frame_equal(combined, expected)
495+
496+
497+
def test_combine_first_duplicates_rows_for_nan_index_values():
498+
# GH39881
499+
df1 = DataFrame(
500+
{"x": [9, 10, 11]},
501+
index=MultiIndex.from_arrays([[1, 2, 3], [np.nan, 5, 6]], names=["a", "b"]),
502+
)
503+
504+
df2 = DataFrame(
505+
{"y": [12, 13, 14]},
506+
index=MultiIndex.from_arrays([[1, 2, 4], [np.nan, 5, 7]], names=["a", "b"]),
507+
)
508+
509+
expected = DataFrame(
510+
{
511+
"x": [9.0, 10.0, 11.0, np.nan],
512+
"y": [12.0, 13.0, np.nan, 14.0],
513+
},
514+
index=MultiIndex.from_arrays(
515+
[[1, 2, 3, 4], [np.nan, 5.0, 6.0, 7.0]], names=["a", "b"]
516+
),
517+
)
518+
combined = df1.combine_first(df2)
519+
tm.assert_frame_equal(combined, expected)

0 commit comments

Comments
 (0)