Skip to content

Commit af030fe

Browse files
committed
restructured test to not rely on reset_index
1 parent caf99a0 commit af030fe

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

pandas/tests/reshape/merge/test_multi.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def test_merge_na_keys(self):
458458

459459
tm.assert_frame_equal(result, expected)
460460

461-
def test_merge_na_datetime_keys_empty_df(self):
461+
def test_merge_datetime_index_empty_df(self):
462462
data = [
463463
[pd.Timestamp("1950-01-01"), "A", 1.5],
464464
[pd.Timestamp("1950-01-02"), "B", 1.5],
@@ -474,16 +474,22 @@ def test_merge_na_datetime_keys_empty_df(self):
474474
frame = DataFrame(data, columns=["date", "panel", "data"]).set_index(
475475
["date", "panel"]
476476
)
477-
478-
other_data = []
479-
other = DataFrame(other_data, columns=["date", "panel", "state"]).set_index(
477+
other = DataFrame(columns=["date", "panel", "state"]).set_index(
480478
["date", "panel"]
481479
)
482-
483-
expected = DataFrame([], columns=["date", "panel", "data", "state"])
484-
expected[["date", "panel", "data"]] = frame.reset_index()[
485-
["date", "panel", "data"]
480+
expected_data = [
481+
[pd.Timestamp("1950-01-01"), "A", 1.5, pd.NA],
482+
[pd.Timestamp("1950-01-02"), "B", 1.5, pd.NA],
483+
[pd.Timestamp("1950-01-03"), "B", 1.5, pd.NA],
484+
[pd.Timestamp("1950-01-04"), "B", np.nan, pd.NA],
485+
[pd.Timestamp("1950-01-05"), "B", 4.0, pd.NA],
486+
[pd.Timestamp("1950-01-06"), "C", 4.0, pd.NA],
487+
[pd.Timestamp("1950-01-07"), "C", np.nan, pd.NA],
488+
[pd.Timestamp("1950-01-08"), "C", 3.0, pd.NA],
489+
[pd.Timestamp("1950-01-09"), "C", 4.0, pd.NA],
486490
]
491+
492+
expected = DataFrame(expected_data, columns=["date", "panel", "data", "state"])
487493
expected = expected.set_index(["date", "panel"])
488494

489495
result = frame.merge(other, how="left", on=["date", "panel"])

0 commit comments

Comments
 (0)