Skip to content

Commit 0627903

Browse files
authored
TST: Add regression test for pivot on empty frame with period dtype (GH62705) (#63003)
1 parent 31942c8 commit 0627903

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/reshape/test_pivot.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,3 +2942,20 @@ def test_pivot_with_pyarrow_categorical(self):
29422942
tm.assert_frame_equal(
29432943
df, df_expected, check_dtype=False, check_column_type=False
29442944
)
2945+
2946+
@pytest.mark.parametrize("freq", ["D", "M", "Q", "Y"])
2947+
def test_pivot_empty_dataframe_period_dtype(self, freq):
2948+
# GH#62705
2949+
2950+
dtype = pd.PeriodDtype(freq=freq)
2951+
df = DataFrame({"index": [], "columns": [], "values": []})
2952+
df = df.astype({"values": dtype})
2953+
result = df.pivot(index="index", columns="columns", values="values")
2954+
2955+
expected_index = Index([], name="index", dtype="float64")
2956+
expected_columns = Index([], name="columns", dtype="float64")
2957+
expected = DataFrame(
2958+
index=expected_index, columns=expected_columns, dtype=dtype
2959+
)
2960+
2961+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)