Skip to content

Commit c58fa84

Browse files
authored
Issue 21932: Added Regression Test for index of pivot_table on empty table (#52809)
1 parent 2ac0da4 commit c58fa84

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pandas/tests/reshape/test_pivot.py

+8
Original file line numberDiff line numberDiff line change
@@ -2598,3 +2598,11 @@ def test_pivot_not_changing_index_name(self):
25982598
expected = df.copy(deep=True)
25992599
df.pivot(index="one", columns="two", values="three")
26002600
tm.assert_frame_equal(df, expected)
2601+
2602+
def test_pivot_table_empty_dataframe_correct_index(self):
2603+
# GH 21932
2604+
df = DataFrame([], columns=["a", "b", "value"])
2605+
pivot = df.pivot_table(index="a", columns="b", values="value", aggfunc="count")
2606+
2607+
expected = Index([], dtype="object", name="b")
2608+
tm.assert_index_equal(pivot.columns, expected)

0 commit comments

Comments
 (0)