Skip to content

TST: Add test for filling new rows through reindexing MultiIndex #37726

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 5 commits into from
Nov 13, 2020
Merged
Changes from 2 commits
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
10 changes: 10 additions & 0 deletions pandas/tests/indexes/multi/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,13 @@ def test_reindex_non_unique():
msg = "cannot handle a non-unique multi-index!"
with pytest.raises(ValueError, match=msg):
a.reindex(new_idx)


def test_reindex_fill_added_rows():
# GH: 23693
i = pd.MultiIndex.from_tuples([("a", "b"), ("d", "e")])
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 use MultiIndex with out the "pd"

Copy link
Member

Choose a reason for hiding this comment

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

and pls avoid 1-letter variable names. mi is a good choice for MultiIndex obj

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

df = pd.DataFrame([[0, 7], [3, 4]], index=i, columns=["x", "y"])
i2 = pd.MultiIndex.from_tuples([("a", "b"), ("d", "e"), ("h", "i")])
result = df.reindex(i2, axis=0, method="ffill")
expected = pd.DataFrame([[0, 7], [3, 4], [3, 4]], index=i2, columns=["x", "y"])
Copy link
Member

Choose a reason for hiding this comment

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

if the method being tested is DataFrame.reindex, then this belongs in tests.frame.method.test_reindex

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, was checking frame/indexing and could not find a reindex file. Moved the test now to the methods folder

tm.assert_frame_equal(result, expected)