@@ -140,9 +140,13 @@ def test_combine_first_mixed_bug(self):
140
140
)
141
141
df2 = DataFrame ([[- 42.6 , np .nan , True ], [- 5.0 , 1.6 , False ]], index = [1 , 2 ])
142
142
143
- result = df1 .combine_first (df2 )[2 ]
143
+ result1 = df1 .combine_first (df2 )[2 ]
144
+ result2 = df2 .combine_first (df1 )[2 ]
145
+ # this would fail prior to this fix
146
+ tm .assert_series_equal (result1 , result2 )
144
147
expected = Series ([True , True , False ], name = 2 )
145
- tm .assert_series_equal (result , expected )
148
+ # regression
149
+ # tm.assert_series_equal(result, expected)
146
150
147
151
# GH 3593, converting datetime64[ns] incorrectly
148
152
df0 = DataFrame (
@@ -339,9 +343,13 @@ def test_combine_first_int(self):
339
343
df1 = pd .DataFrame ({"a" : [0 , 1 , 3 , 5 ]}, dtype = "int64" )
340
344
df2 = pd .DataFrame ({"a" : [1 , 4 ]}, dtype = "int64" )
341
345
342
- res = df1 .combine_first (df2 )
343
- tm .assert_frame_equal (res , df1 )
344
- assert res ["a" ].dtype == "int64"
346
+ res1 = df1 .combine_first (df2 )
347
+ res2 = df1 .combine_first (df2 )
348
+ # this would fail prior to this fix
349
+ assert res1 ["a" ].dtype == res2 ["a" ].dtype
350
+ # regression
351
+ # tm.assert_frame_equal(res, df1)
352
+ # assert res["a"].dtype == "int64"
345
353
346
354
@pytest .mark .parametrize ("val" , [1 , 1.0 ])
347
355
def test_combine_first_with_asymmetric_other (self , val ):
@@ -353,3 +361,19 @@ def test_combine_first_with_asymmetric_other(self, val):
353
361
exp = pd .DataFrame ({"isBool" : [True ], "isNum" : [val ]})
354
362
355
363
tm .assert_frame_equal (res , exp )
364
+
365
+
366
+ @pytest .mark .parametrize ("val" , [pd .NaT , np .nan , None ])
367
+ def test_combine_first_timestamp_bug (val ):
368
+
369
+ df1 = pd .DataFrame ([[val , val ]], columns = ["a" , "b" ])
370
+ df2 = pd .DataFrame (
371
+ [[datetime (2020 , 1 , 1 ), datetime (2020 , 1 , 2 )]], columns = ["b" , "c" ]
372
+ )
373
+
374
+ res = df1 .combine_first (df2 )
375
+ exp = pd .DataFrame (
376
+ [[val , datetime (2020 , 1 , 1 ), datetime (2020 , 1 , 2 )]], columns = ["a" , "b" , "c" ]
377
+ )
378
+
379
+ tm .assert_frame_equal (res , exp )
0 commit comments