Skip to content

Commit fe1d3d8

Browse files
committed
restructured test to not rely on reset_index
1 parent a064c7c commit fe1d3d8

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

pandas/tests/reshape/merge/test_multi.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ 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):
463+
def test_merge_datetime_index_empty_df(self):
464464
data = [
465465
[pd.Timestamp("1950-01-01"), "A", 1.5],
466466
[pd.Timestamp("1950-01-02"), "B", 1.5],
@@ -476,16 +476,22 @@ def test_merge_na_datetime_keys_empty_df(self):
476476
frame = DataFrame(data, columns=["date", "panel", "data"]).set_index(
477477
["date", "panel"]
478478
)
479-
480-
other_data = []
481-
other = DataFrame(other_data, columns=["date", "panel", "state"]).set_index(
479+
other = DataFrame(columns=["date", "panel", "state"]).set_index(
482480
["date", "panel"]
483481
)
484-
485-
expected = DataFrame([], columns=["date", "panel", "data", "state"])
486-
expected[["date", "panel", "data"]] = frame.reset_index()[
487-
["date", "panel", "data"]
482+
expected_data = [
483+
[pd.Timestamp("1950-01-01"), "A", 1.5, pd.NA],
484+
[pd.Timestamp("1950-01-02"), "B", 1.5, pd.NA],
485+
[pd.Timestamp("1950-01-03"), "B", 1.5, pd.NA],
486+
[pd.Timestamp("1950-01-04"), "B", np.nan, pd.NA],
487+
[pd.Timestamp("1950-01-05"), "B", 4.0, pd.NA],
488+
[pd.Timestamp("1950-01-06"), "C", 4.0, pd.NA],
489+
[pd.Timestamp("1950-01-07"), "C", np.nan, pd.NA],
490+
[pd.Timestamp("1950-01-08"), "C", 3.0, pd.NA],
491+
[pd.Timestamp("1950-01-09"), "C", 4.0, pd.NA],
488492
]
493+
494+
expected = DataFrame(expected_data, columns=["date", "panel", "data", "state"])
489495
expected = expected.set_index(["date", "panel"])
490496

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

0 commit comments

Comments
 (0)