From 03ff6e8f80dec7d7e160a154e2fc00f281a4b35c Mon Sep 17 00:00:00 2001 From: Mirja Hollmann Date: Thu, 20 Apr 2023 18:32:23 +0000 Subject: [PATCH 1/5] add regression test --- pandas/tests/reshape/test_pivot.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 3fc617b91b866..9e551c37e3ffd 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2598,3 +2598,14 @@ 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 = pd.Index([], dtype='object', name='b') + tm.assert_index_equal(pivot.columns, expected) + + From 090d02e1e72aebffe7f396d80a2708987ef6bb54 Mon Sep 17 00:00:00 2001 From: Mirja Hollmann Date: Fri, 21 Apr 2023 07:01:16 +0000 Subject: [PATCH 2/5] formatting --- pandas/tests/reshape/test_pivot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 9e551c37e3ffd..2f41745b3da7d 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2600,12 +2600,12 @@ def test_pivot_not_changing_index_name(self): 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') + # GH 21932 + df = DataFrame([], columns=["a", "b", "value"]) + pivot = df.pivot_table(index="a", columns="b", values="value", + aggfunc="count") - expected = pd.Index([], dtype='object', name='b') + expected = pd.Index([], dtype="object", name="b") tm.assert_index_equal(pivot.columns, expected) From 359b8d5c78dfcc31489b2470d9375be7c31713d9 Mon Sep 17 00:00:00 2001 From: Mirja Hollmann Date: Fri, 21 Apr 2023 12:21:51 +0000 Subject: [PATCH 3/5] format --- pandas/tests/reshape/test_pivot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 2f41745b3da7d..2fe1f37fb1f1b 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2602,8 +2602,7 @@ def test_pivot_not_changing_index_name(self): 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") + pivot = df.pivot_table(index="a", columns="b", values="value", aggfunc="count") expected = pd.Index([], dtype="object", name="b") tm.assert_index_equal(pivot.columns, expected) From aec2e06efd599b6e21a7d27cea2c07ae17f51e16 Mon Sep 17 00:00:00 2001 From: Mirja Hollmann Date: Fri, 21 Apr 2023 13:41:17 +0000 Subject: [PATCH 4/5] rm newlines --- pandas/tests/reshape/test_pivot.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 2fe1f37fb1f1b..bec6922acfa13 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2605,6 +2605,4 @@ def test_pivot_table_empty_dataframe_correct_index(self): pivot = df.pivot_table(index="a", columns="b", values="value", aggfunc="count") expected = pd.Index([], dtype="object", name="b") - tm.assert_index_equal(pivot.columns, expected) - - + tm.assert_index_equal(pivot.columns, expected) \ No newline at end of file From 198a1b15e840388f7eaf32e186569647c03a5ce3 Mon Sep 17 00:00:00 2001 From: Mirja Hollmann Date: Sat, 22 Apr 2023 05:57:51 +0000 Subject: [PATCH 5/5] changes from precommit --- pandas/tests/reshape/test_pivot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index bec6922acfa13..efd5ec2f0868f 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2604,5 +2604,5 @@ def test_pivot_table_empty_dataframe_correct_index(self): df = DataFrame([], columns=["a", "b", "value"]) pivot = df.pivot_table(index="a", columns="b", values="value", aggfunc="count") - expected = pd.Index([], dtype="object", name="b") - tm.assert_index_equal(pivot.columns, expected) \ No newline at end of file + expected = Index([], dtype="object", name="b") + tm.assert_index_equal(pivot.columns, expected)