-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
regression fix for merging DF with datetime index with empty DF #36897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
16a7844
029447d
30d0c90
08d0ef1
3da79a4
b3a5261
d85af30
70651d1
a70c0ff
ce3a1fa
83be75e
fe1335e
e5045f3
9fb0687
0f856dd
b1c7519
84822c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,6 +481,56 @@ def test_merge_datetime_index(self, klass): | |
result = df.merge(df, on=[df.index.year], how="inner") | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_merge_datetime_multi_index_empty_df(self): | ||
|
||
PCerles marked this conversation as resolved.
Show resolved
Hide resolved
|
||
midx1 = pd.MultiIndex.from_tuples( | ||
[[pd.Timestamp("1950-01-01"), "A"], [pd.Timestamp("1950-01-02"), "B"]], | ||
names=["date", "panel"], | ||
) | ||
left = DataFrame( | ||
data={ | ||
"data": [1.5, 1.5], | ||
}, | ||
index=midx1, | ||
PCerles marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
midx2 = pd.MultiIndex.from_tuples([], names=["date", "panel"]) | ||
|
||
right = DataFrame(index=midx2, columns=["state"]) | ||
|
||
midx3 = pd.MultiIndex.from_tuples( | ||
[[pd.Timestamp("1950-01-01"), "A"], [pd.Timestamp("1950-01-02"), "B"]], | ||
names=["date", "panel"], | ||
) | ||
|
||
expected_left_merge = DataFrame( | ||
data={ | ||
"data": [1.5, 1.5], | ||
"state": [None, None], | ||
}, | ||
index=midx3, | ||
) | ||
|
||
expected_right_merge = DataFrame( | ||
data={ | ||
"state": [None, None], | ||
"data": [1.5, 1.5], | ||
}, | ||
index=midx3, | ||
) | ||
|
||
result_left_merge = left.merge(right, how="left", on=["date", "panel"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you paramaterize this; it is very hard to understand what is equal to what here. you can put the expected things in the parametr. I would like to hard code the result data frame (rather than trying to do operations to get it). its very hard to read otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I parametrized the merge type in my commit -- did you want me to explicitly construct an expected data frame in the parametrize call here? https://github.com/pandas-dev/pandas/pull/36897/files#diff-513c054eb6b1b4b5767980db8c8dc0bd93f7ea55df9facea3465bfac11785474R509 |
||
tm.assert_frame_equal(result_left_merge, expected_left_merge) | ||
|
||
result_right_merge = right.merge(left, how="right", on=["date", "panel"]) | ||
tm.assert_frame_equal(result_right_merge, expected_right_merge) | ||
|
||
result_left_join = left.join(right, how="left") | ||
tm.assert_frame_equal(result_left_join, expected_left_merge) | ||
|
||
result_right_join = right.join(left, how="right") | ||
tm.assert_frame_equal(result_right_join, expected_right_merge) | ||
|
||
def test_join_multi_levels(self): | ||
|
||
# GH 3662 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry can you move to the reshaping section