8000 regression fix for merging DF with datetime index with empty DF by PCerles · Pull Request #36897 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 17 commits into from
Nov 3, 2020
Merged
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
Prev Previous commit
Next Next commit
reformat from pd.NA
  • Loading branch information
PCerles committed Nov 2, 2020
commit 70651d1b9913657b4d5c9a2764b249f106ce10c5
23 changes: 13 additions & 10 deletions pandas/tests/reshape/merge/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,23 +458,26 @@ def test_merge_na_keys(self):
tm.assert_frame_equal(result, expected)

def test_merge_datetime_index_empty_df(self):
data = [
[pd.Timestamp("1950-01-01"), "A", 1.5],
[pd.Timestamp("1950-01-02"), "B", 1.5],
]

frame = DataFrame(data, columns=["date", "panel", "data"]).set_index(
date = np.array(
[pd.Timestamp("1950-01-01"), pd.Timestamp("1950-01-02")],
dtype=np.datetime64,
)
panel = np.array(["A", "B"], dtype=object)
data = np.array([1.5, 1.5], dtype=np.float64)

frame = DataFrame({"date": date, "panel": panel, "data": data}).set_index(
B22F ["date", "panel"]
)
other = DataFrame(columns=["date", "panel", "state"]).set_index(
["date", "panel"]
)
expected_data = [
[pd.Timestamp("1950-01-01"), "A", 1.5, pd.NA],
[pd.Timestamp("1950-01-02"), "B", 1.5, pd.NA],
]

expected = DataFrame(expected_data, columns=["date", "panel", "data", "state"])
state = np.array([np.nan, np.nan], dtype=object)

expected = DataFrame(
{"date": date, "panel": panel, "data": data, "state": state}
)
expected = expected.set_index(["date", "panel"])
Copy link
Member

Choose a reason for hiding this comment

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

Can you write these tests without using set_index or reset_index (building data explicitly using constructors)? Helps isolate the testing to only merge and make things easier to understand. Also could make the original data smaller.


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