diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 1bb4e35e041d0..22a73ae1b5ddb 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2942,3 +2942,20 @@ def test_pivot_with_pyarrow_categorical(self): tm.assert_frame_equal( df, df_expected, check_dtype=False, check_column_type=False ) + + @pytest.mark.parametrize("freq", ["D", "M", "Q", "Y"]) + def test_pivot_empty_dataframe_period_dtype(self, freq): + # GH#62705 + + dtype = pd.PeriodDtype(freq=freq) + df = DataFrame({"index": [], "columns": [], "values": []}) + df = df.astype({"values": dtype}) + result = df.pivot(index="index", columns="columns", values="values") + + expected_index = Index([], name="index", dtype="float64") + expected_columns = Index([], name="columns", dtype="float64") + expected = DataFrame( + index=expected_index, columns=expected_columns, dtype=dtype + ) + + tm.assert_frame_equal(result, expected)