Skip to content

Commit 3ed5aea

Browse files
committed
fix import and explicitly construct multi indexes
1 parent db73e7c commit 3ed5aea

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

pandas/tests/reshape/merge/test_multi.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import numpy as np
22
from numpy.random import randn
3+
import pytest
4+
35
import pandas as pd
46
from pandas import DataFrame, Index, MultiIndex, Series
57
import pandas._testing as tm
68
from pandas.core.reshape.concat import concat
79
from pandas.core.reshape.merge import merge
8-
import pytest
910

1011

1112
@pytest.fixture
@@ -840,25 +841,32 @@ def test_join_multi_wrong_order(self):
840841

841842
def test_merge_datetime_index_empty_df():
842843

844+
midx1 = pd.MultiIndex.from_tuples(
845+
[[pd.Timestamp("1950-01-01"), "A"], [pd.Timestamp("1950-01-02"), "B"]],
846+
names=["date", "panel"],
847+
)
843848
frame = DataFrame(
844-
{
845-
"date": [pd.Timestamp("1950-01-01"), pd.Timestamp("1950-01-02")],
846-
"panel": ["A", "B"],
849+
data={
847850
"data": [1.5, 1.5],
848-
}
849-
).set_index(["date", "panel"])
850-
other = DataFrame(columns=["date", "panel", "state"]).set_index(["date", "panel"])
851+
},
852+
index=midx1,
853+
)
854+
855+
midx2 = pd.MultiIndex.from_tuples([], names=["date", "panel"])
856+
857+
other = DataFrame(index=midx2, columns=["state"])
858+
859+
midx3 = pd.MultiIndex.from_tuples(
860+
[[pd.Timestamp("1950-01-01"), "A"], [pd.Timestamp("1950-01-02"), "B"]],
861+
names=["date", "panel"],
862+
)
851863

852864
expected = DataFrame(
853-
{
854-
"date": [pd.Timestamp("1950-01-01"), pd.Timestamp("1950-01-02")],
855-
"panel": ["A", "B"],
865+
data={
856866
"data": [1.5, 1.5],
857867
"state": [None, None],
858-
}
868+
},
869+
index=midx3,
859870
)
860-
expected = expected.set_index(["date", "panel"])
861-
862871
result = frame.merge(other, how="left", on=["date", "panel"])
863-
864872
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)