From 5dd1b38e3beaefa15909a73b3eb83fb44daa5624 Mon Sep 17 00:00:00 2001 From: hulusierin Date: Tue, 7 Oct 2025 16:36:26 +0100 Subject: [PATCH] TST: Replace ensure_clean with temp_file in test_file_handling.py --- .../tests/io/pytables/test_file_handling.py | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/pandas/tests/io/pytables/test_file_handling.py b/pandas/tests/io/pytables/test_file_handling.py index 295c3b72ba5e2..2ea2ac632c992 100644 --- a/pandas/tests/io/pytables/test_file_handling.py +++ b/pandas/tests/io/pytables/test_file_handling.py @@ -161,30 +161,28 @@ def test_reopen_handle(tmp_path, setup_path): assert not store.is_open -def test_open_args(setup_path, using_infer_string): - with tm.ensure_clean(setup_path) as path: - df = DataFrame( - 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), - ) +def test_open_args(tmp_path, setup_path, using_infer_string): + path = tmp_path / setup_path + df = DataFrame( + 1.1 * np.arange(120).reshape((30, 4)), + columns=Index(list("ABCD"), dtype=object), + index=Index([f"i-{i}" for i in range(30)], dtype=object), + ) - # create an in memory store - store = HDFStore( - path, mode="a", driver="H5FD_CORE", driver_core_backing_store=0 - ) - store["df"] = df - store.append("df2", df) + # create an in memory store + store = HDFStore(path, mode="a", driver="H5FD_CORE", driver_core_backing_store=0) + store["df"] = df + store.append("df2", df) - expected = df.copy() - if using_infer_string: - expected.index = expected.index.astype("str") - expected.columns = expected.columns.astype("str") + expected = df.copy() + if using_infer_string: + expected.index = expected.index.astype("str") + expected.columns = expected.columns.astype("str") - tm.assert_frame_equal(store["df"], expected) - tm.assert_frame_equal(store["df2"], expected) + tm.assert_frame_equal(store["df"], expected) + tm.assert_frame_equal(store["df2"], expected) - store.close() + store.close() # the file should not have actually been written assert not os.path.exists(path) @@ -507,7 +505,7 @@ def test_multiple_open_close(tmp_path, setup_path): store.df -def test_fspath(): - with tm.ensure_clean("foo.h5") as path: - with HDFStore(path) as store: - assert os.fspath(store) == str(path) +def test_fspath(tmp_path): + path = tmp_path / "foo.h5" + with HDFStore(path) as store: + assert os.fspath(store) == str(path)