From 658b2b86f351ca5f03514ce82ea268b98f1cebc1 Mon Sep 17 00:00:00 2001 From: paradox-lab <57354735+paradox-lab@users.noreply.github.com> Date: Wed, 21 Sep 2022 01:44:55 +0800 Subject: [PATCH] TST: add test case for PeriodIndex in HDFStore(GH7796) (#48618) * TST: add test case for PeriodIndex in HDFStore * TST: add test case for PeriodIndex in HDFStore * use pytest.mark.parameterize instead --- pandas/tests/io/pytables/test_put.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index d4d95186110f8..4b3fcf4e96cad 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -365,3 +365,17 @@ def make_index(names=None): ) store.append("df", df) tm.assert_frame_equal(store.select("df"), df) + + +@pytest.mark.parametrize("format", ["fixed", "table"]) +def test_store_periodindex(setup_path, format): + # GH 7796 + # test of PeriodIndex in HDFStore + df = DataFrame( + np.random.randn(5, 1), index=pd.period_range("20220101", freq="M", periods=5) + ) + + with ensure_clean_path(setup_path) as path: + df.to_hdf(path, "df", mode="w", format=format) + expected = pd.read_hdf(path, "df") + tm.assert_frame_equal(df, expected)