Skip to content

Commit 175588d

Browse files
committed
added test
1 parent aafdd0f commit 175588d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pandas/tests/reshape/merge/test_multi.py

+32
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,38 @@ def test_merge_na_keys(self):
460460

461461
tm.assert_frame_equal(result, expected)
462462

463+
def test_merge_na_datetime_keys_empty_df(self):
464+
data = [
465+
[pd.Timestamp("1950-01-01"), "A", 1.5],
466+
[pd.Timestamp("1950-01-01"), "B", 1.5],
467+
[pd.Timestamp("1950-01-01"), "B", 1.5],
468+
[pd.Timestamp("1950-01-01"), "B", np.nan],
469+
[pd.Timestamp("1950-01-01"), "B", 4.0],
470+
[pd.Timestamp("1950-01-01"), "C", 4.0],
471+
[pd.Timestamp("1950-01-01"), "C", np.nan],
472+
[pd.Timestamp("1950-01-01"), "C", 3.0],
473+
[pd.Timestamp("1950-01-01"), "C", 4.0],
474+
]
475+
476+
frame = DataFrame(data, columns=["date", "panel", "data"]).set_index(
477+
["date", "panel"]
478+
)
479+
480+
other_data = []
481+
other = DataFrame(other_data, columns=["date", "panel", "state"]).set_index(
482+
["date", "panel"]
483+
)
484+
485+
expected = DataFrame([], columns=["date", "panel", "data", "state"])
486+
expected[["date", "panel", "data"]] = frame.reset_index()[
487+
["date", "panel", "data"]
488+
]
489+
expected = expected.set_index(["date", "panel"])
490+
491+
result = frame.merge(other, how="left", on=["date", "panel"])
492+
493+
tm.assert_frame_equal(result, expected)
494+
463495
@pytest.mark.parametrize("klass", [None, np.asarray, Series, Index])
464496
def test_merge_datetime_index(self, klass):
465497
# see gh-19038

0 commit comments

Comments
 (0)