@@ -457,7 +457,7 @@ def test_merge_na_keys(self):
457
457
458
458
tm .assert_frame_equal (result , expected )
459
459
460
- def test_merge_na_datetime_keys_empty_df (self ):
460
+ def test_merge_datetime_index_empty_df (self ):
461
461
data = [
462
462
[pd .Timestamp ("1950-01-01" ), "A" , 1.5 ],
463
463
[pd .Timestamp ("1950-01-02" ), "B" , 1.5 ],
@@ -473,16 +473,22 @@ def test_merge_na_datetime_keys_empty_df(self):
473
473
frame = DataFrame (data , columns = ["date" , "panel" , "data" ]).set_index (
474
474
["date" , "panel" ]
475
475
)
476
-
477
- other_data = []
478
- other = DataFrame (other_data , columns = ["date" , "panel" , "state" ]).set_index (
476
+ other = DataFrame (columns = ["date" , "panel" , "state" ]).set_index (
479
477
["date" , "panel" ]
480
478
)
481
-
482
- expected = DataFrame ([], columns = ["date" , "panel" , "data" , "state" ])
483
- expected [["date" , "panel" , "data" ]] = frame .reset_index ()[
484
- ["date" , "panel" , "data" ]
479
+ expected_data = [
480
+ [pd .Timestamp ("1950-01-01" ), "A" , 1.5 , pd .NA ],
481
+ [pd .Timestamp ("1950-01-02" ), "B" , 1.5 , pd .NA ],
482
+ [pd .Timestamp ("1950-01-03" ), "B" , 1.5 , pd .NA ],
483
+ [pd .Timestamp ("1950-01-04" ), "B" , np .nan , pd .NA ],
484
+ [pd .Timestamp ("1950-01-05" ), "B" , 4.0 , pd .NA ],
485
+ [pd .Timestamp ("1950-01-06" ), "C" , 4.0 , pd .NA ],
486
+ [pd .Timestamp ("1950-01-07" ), "C" , np .nan , pd .NA ],
487
+ [pd .Timestamp ("1950-01-08" ), "C" , 3.0 , pd .NA ],
488
+ [pd .Timestamp ("1950-01-09" ), "C" , 4.0 , pd .NA ],
485
489
]
490
+
491
+ expected = DataFrame (expected_data , columns = ["date" , "panel" , "data" , "state" ])
486
492
expected = expected .set_index (["date" , "panel" ])
487
493
488
494
result = frame .merge (other , how = "left" , on = ["date" , "panel" ])
0 commit comments