From 802541f9c2073e7d82c45bb13a6ca464c40417d7 Mon Sep 17 00:00:00 2001 From: luzhenxiong <397132445@qq.com> Date: Sun, 18 Sep 2022 19:01:53 +0800 Subject: [PATCH 1/3] TST: add test case for PeriodIndex in HDFStore --- pandas/tests/io/pytables/test_put.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index d4d95186110f8..c7797ab7af648 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -365,3 +365,18 @@ def make_index(names=None): ) store.append("df", df) tm.assert_frame_equal(store.select("df"), df) + + +def test_store_periodindex(setup_path): + # GH 7796 + # test of PeriodIndex in HDFStore + df = pd.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, 'fixed', mode='w', format='fixed') + fixed = pd.read_hdf(path, 'fixed') + tm.assert_frame_equal(df, fixed) + + df.to_hdf(path, 'table', mode='w', format='table') + table = pd.read_hdf(path, 'table') + tm.assert_frame_equal(df, table) From 5cb23b49a6d5bded624ec1d339584d784fd3d5a8 Mon Sep 17 00:00:00 2001 From: luzhenxiong <397132445@qq.com> Date: Sun, 18 Sep 2022 20:54:55 +0800 Subject: [PATCH 2/3] TST: add test case for PeriodIndex in HDFStore --- pandas/tests/io/pytables/test_put.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index c7797ab7af648..ebd975c090220 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -370,13 +370,15 @@ def make_index(names=None): def test_store_periodindex(setup_path): # GH 7796 # test of PeriodIndex in HDFStore - df = pd.DataFrame(np.random.randn(5, 1), index=pd.period_range('20220101', freq='M', periods=5)) + 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, 'fixed', mode='w', format='fixed') - fixed = pd.read_hdf(path, 'fixed') + df.to_hdf(path, "fixed", mode="w", format="fixed") + fixed = pd.read_hdf(path, "fixed") tm.assert_frame_equal(df, fixed) - df.to_hdf(path, 'table', mode='w', format='table') - table = pd.read_hdf(path, 'table') + df.to_hdf(path, "table", mode="w", format="table") + table = pd.read_hdf(path, "table") tm.assert_frame_equal(df, table) From 664b332c76ff6948f81367cb84769c7a243fe8bd Mon Sep 17 00:00:00 2001 From: luzhenxiong <397132445@qq.com> Date: Tue, 20 Sep 2022 10:36:57 +0800 Subject: [PATCH 3/3] use pytest.mark.parameterize instead --- pandas/tests/io/pytables/test_put.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index ebd975c090220..4b3fcf4e96cad 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -367,7 +367,8 @@ def make_index(names=None): tm.assert_frame_equal(store.select("df"), df) -def test_store_periodindex(setup_path): +@pytest.mark.parametrize("format", ["fixed", "table"]) +def test_store_periodindex(setup_path, format): # GH 7796 # test of PeriodIndex in HDFStore df = DataFrame( @@ -375,10 +376,6 @@ def test_store_periodindex(setup_path): ) with ensure_clean_path(setup_path) as path: - df.to_hdf(path, "fixed", mode="w", format="fixed") - fixed = pd.read_hdf(path, "fixed") - tm.assert_frame_equal(df, fixed) - - df.to_hdf(path, "table", mode="w", format="table") - table = pd.read_hdf(path, "table") - tm.assert_frame_equal(df, table) + df.to_hdf(path, "df", mode="w", format=format) + expected = pd.read_hdf(path, "df") + tm.assert_frame_equal(df, expected)