Skip to content

Commit

Permalink
Issue 21932: Added Regression Test for index of pivot_table on empty …
Browse files Browse the repository at this point in the history
…table (#52809)
  • Loading branch information
MirijaH committed Apr 22, 2023
1 parent 2ac0da4 commit c58fa84
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,3 +2598,11 @@ def test_pivot_not_changing_index_name(self):
expected = df.copy(deep=True)
df.pivot(index="one", columns="two", values="three")
tm.assert_frame_equal(df, expected)

def test_pivot_table_empty_dataframe_correct_index(self):
# GH 21932
df = DataFrame([], columns=["a", "b", "value"])
pivot = df.pivot_table(index="a", columns="b", values="value", aggfunc="count")

expected = Index([], dtype="object", name="b")
tm.assert_index_equal(pivot.columns, expected)

0 comments on commit c58fa84

Please sign in to comment.