diff --git a/pandas/tests/io/pytables/test_complex.py b/pandas/tests/io/pytables/test_complex.py index 80e7664d1969e..d0c477c004661 100644 --- a/pandas/tests/io/pytables/test_complex.py +++ b/pandas/tests/io/pytables/test_complex.py @@ -4,12 +4,11 @@ import pandas as pd from pandas import ( DataFrame, + HDFStore, Series, + read_hdf, ) import pandas._testing as tm -from pandas.tests.io.pytables.common import ensure_clean_store - -from pandas.io.pytables import read_hdf def test_complex_fixed(tmp_path, setup_path): @@ -103,7 +102,8 @@ def test_complex_mixed_table(tmp_path, setup_path): index=list("abcd"), ) - with ensure_clean_store(setup_path) as store: + path = tmp_path / setup_path + with HDFStore(path) as store: store.append("df", df, data_columns=["A", "B"]) result = store.select("df", where="A>2") tm.assert_frame_equal(df.loc[df.A > 2], result) @@ -139,7 +139,7 @@ def test_complex_across_dimensions(tmp_path, setup_path): tm.assert_frame_equal(df, reread) -def test_complex_indexing_error(setup_path): +def test_complex_indexing_error(tmp_path, setup_path): complex128 = np.array( [1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j], dtype=np.complex128 ) @@ -156,7 +156,8 @@ def test_complex_indexing_error(setup_path): "values to data_columns when initializing the table." ) - with ensure_clean_store(setup_path) as store: + path = tmp_path / setup_path + with HDFStore(path) as store: with pytest.raises(TypeError, match=msg): store.append("df", df, data_columns=["C"]) @@ -183,7 +184,7 @@ def test_complex_series_error(tmp_path, setup_path): tm.assert_series_equal(s, reread) -def test_complex_append(setup_path): +def test_complex_append(tmp_path, setup_path): df = DataFrame( { "a": np.random.default_rng(2).standard_normal(100).astype(np.complex128), @@ -191,7 +192,8 @@ def test_complex_append(setup_path): } ) - with ensure_clean_store(setup_path) as store: + path = tmp_path / setup_path + with HDFStore(path, mode="a") as store: store.append("df", df, data_columns=["b"]) store.append("df", df) result = store.select("df") diff --git a/pandas/tests/io/pytables/test_file_handling.py b/pandas/tests/io/pytables/test_file_handling.py index 2ea2ac632c992..94cba10efcc64 100644 --- a/pandas/tests/io/pytables/test_file_handling.py +++ b/pandas/tests/io/pytables/test_file_handling.py @@ -24,7 +24,6 @@ ) from pandas.tests.io.pytables.common import ( _maybe_remove, - ensure_clean_store, tables, ) @@ -188,8 +187,8 @@ def test_open_args(tmp_path, setup_path, using_infer_string): assert not os.path.exists(path) -def test_flush(setup_path): - with ensure_clean_store(setup_path) as store: +def test_flush(tmp_path, setup_path): + with HDFStore(tmp_path / setup_path) as store: store["a"] = Series(range(5)) store.flush() store.flush(fsync=True) @@ -316,8 +315,8 @@ def test_complibs(tmp_path, lvl, lib, request): @pytest.mark.skipif( not is_platform_little_endian(), reason="reason platform is not little endian" ) -def test_encoding(setup_path): - with ensure_clean_store(setup_path) as store: +def test_encoding(tmp_path, setup_path): + with HDFStore(tmp_path / setup_path) as store: df = DataFrame({"A": "foo", "B": "bar"}, index=range(5)) df.loc[2, "A"] = np.nan df.loc[3, "B"] = np.nan