Skip to content

Commit b3a5261

Browse files
committed
restructured test to not rely on reset_index
1 parent 3da79a4 commit b3a5261

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
@@ -457,7 +457,7 @@ def test_merge_na_keys(self):
457457

458458
tm.assert_frame_equal(result, expected)
459459

460-
def test_merge_na_datetime_keys_empty_df(self):
460+
def test_merge_datetime_index_empty_df(self):
461461
data = [
462462
[pd.Timestamp("1950-01-01"), "A", 1.5],
463463
[pd.Timestamp("1950-01-02"), "B", 1.5],
@@ -473,16 +473,22 @@ def test_merge_na_datetime_keys_empty_df(self):
473473
frame = DataFrame(data, columns=["date", "panel", "data"]).set_index(
474474
["date", "panel"]
475475
)
476-
477-
other_data = []
478-
other = DataFrame(other_data, columns=["date", "panel", "state"]).set_index(
476+
other = DataFrame(columns=["date", "panel", "state"]).set_index(
479477
["date", "panel"]
480478
)
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],
485489
]
490+
491+
expected = DataFrame(expected_data, columns=["date", "panel", "data", "state"])
486492
expected = expected.set_index(["date", "panel"])
487493

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

0 commit comments

Comments
 (0)