Skip to content

TST: add test case for sort_index on multiindexed Frame with sparse cols #36236

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 2 commits into from
Sep 12, 2020
Merged
Changes from all 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
15 changes: 15 additions & 0 deletions pandas/tests/frame/methods/test_sort_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,18 @@ def test_changes_length_raises(self):
df = pd.DataFrame({"A": [1, 2, 3]})
with pytest.raises(ValueError, match="change the shape"):
df.sort_index(key=lambda x: x[:1])

def test_sort_index_multiindex_sparse_column(self):
# GH 29735, testing that sort_index on a multiindexed frame with sparse
# columns fills with 0.
expected = pd.DataFrame(
{
i: pd.array([0.0, 0.0, 0.0, 0.0], dtype=pd.SparseDtype("float64", 0.0))
for i in range(0, 4)
},
index=pd.MultiIndex.from_product([[1, 2], [1, 2]]),
)

result = expected.sort_index(level=0)

tm.assert_frame_equal(result, expected)