Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pandas/tests/frame/methods/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ def test_join_multiindex_leftright(self):
tm.assert_frame_equal(df1.join(df2, how="right"), exp)
tm.assert_frame_equal(df2.join(df1, how="left"), exp[["value2", "value1"]])

def test_join_multiindex_dates(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 'join' is whats being tested here, can you avoid using groupby and first?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will change the test

# GH 33692
date = pd.Timestamp(2000, 1, 1).date()

# creates dataframes
df1 = DataFrame({"index_0": 0, "date": date, "col1": [0]})
df2 = DataFrame({"index_0": 0, "date": date, "col2": [0]})
df1 = df1.groupby(by=["index_0", "date"]).first()
df2 = df2.groupby(by=["index_0", "date"]).first()

multi_index = MultiIndex.from_tuples([(0, date)], names=["index_0", "date"])
df3 = DataFrame(index=multi_index, columns=["col3"], data=[0])

expected = (
DataFrame(
{"index_0": 0, "date": date, "col1": [0], "col2": [0], "col3": [0]}
)
.groupby(by=["index_0", "date"])
.first()
)
result = df1.join([df2, df3])
tm.assert_equal(result, expected)

def test_merge_join_different_levels(self):
# GH#9455

Expand Down