Skip to content

Commit c6e3af7

Browse files
authored
TST: add test case for sort_index on multiindexed Frame with sparse columns (#36236)
1 parent 6100425 commit c6e3af7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/tests/frame/methods/test_sort_index.py

+15
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,18 @@ def test_changes_length_raises(self):
739739
df = pd.DataFrame({"A": [1, 2, 3]})
740740
with pytest.raises(ValueError, match="change the shape"):
741741
df.sort_index(key=lambda x: x[:1])
742+
743+
def test_sort_index_multiindex_sparse_column(self):
744+
# GH 29735, testing that sort_index on a multiindexed frame with sparse
745+
# columns fills with 0.
746+
expected = pd.DataFrame(
747+
{
748+
i: pd.array([0.0, 0.0, 0.0, 0.0], dtype=pd.SparseDtype("float64", 0.0))
749+
for i in range(0, 4)
750+
},
751+
index=pd.MultiIndex.from_product([[1, 2], [1, 2]]),
752+
)
753+
754+
result = expected.sort_index(level=0)
755+
756+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)