Skip to content

Commit f981616

Browse files
Merge branch 'micol-altomare-replace-ensure-clean-store' of https://github.com/micol-altomare/pandas into micol-altomare-replace-ensure-clean-store
2 parents 1b5b02c + 67c22f0 commit f981616

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

pandas/tests/io/pytables/test_complex.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import pandas as pd
55
from pandas import (
66
DataFrame,
7+
HDFStore,
78
Series,
89
)
910
import pandas._testing as tm
10-
from pandas.tests.io.pytables.common import ensure_clean_store
1111

1212
from pandas.io.pytables import read_hdf
1313

@@ -103,7 +103,7 @@ def test_complex_mixed_table(tmp_path, setup_path):
103103
index=list("abcd"),
104104
)
105105

106-
with ensure_clean_store(setup_path) as store:
106+
with HDFStore(tmp_path / setup_path) as store:
107107
store.append("df", df, data_columns=["A", "B"])
108108
result = store.select("df", where="A>2")
109109
tm.assert_frame_equal(df.loc[df.A > 2], result)
@@ -139,7 +139,7 @@ def test_complex_across_dimensions(tmp_path, setup_path):
139139
tm.assert_frame_equal(df, reread)
140140

141141

142-
def test_complex_indexing_error(setup_path):
142+
def test_complex_indexing_error(tmp_path, setup_path):
143143
complex128 = np.array(
144144
[1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j], dtype=np.complex128
145145
)
@@ -156,7 +156,7 @@ def test_complex_indexing_error(setup_path):
156156
"values to data_columns when initializing the table."
157157
)
158158

159-
with ensure_clean_store(setup_path) as store:
159+
with HDFStore(tmp_path / setup_path) as store:
160160
with pytest.raises(TypeError, match=msg):
161161
store.append("df", df, data_columns=["C"])
162162

@@ -183,15 +183,15 @@ def test_complex_series_error(tmp_path, setup_path):
183183
tm.assert_series_equal(s, reread)
184184

185185

186-
def test_complex_append(setup_path):
186+
def test_complex_append(tmp_path, setup_path):
187187
df = DataFrame(
188188
{
189189
"a": np.random.default_rng(2).standard_normal(100).astype(np.complex128),
190190
"b": np.random.default_rng(2).standard_normal(100),
191191
}
192192
)
193193

194-
with ensure_clean_store(setup_path) as store:
194+
with HDFStore(tmp_path / setup_path) as store:
195195
store.append("df", df, data_columns=["b"])
196196
store.append("df", df)
197197
result = store.select("df")

pandas/tests/io/pytables/test_file_handling.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
)
2525
from pandas.tests.io.pytables.common import (
2626
_maybe_remove,
27-
ensure_clean_store,
2827
tables,
2928
)
3029

@@ -188,8 +187,8 @@ def test_open_args(tmp_path, setup_path, using_infer_string):
188187
assert not os.path.exists(path)
189188

190189

191-
def test_flush(setup_path):
192-
with ensure_clean_store(setup_path) as store:
190+
def test_flush(tmp_path, setup_path):
191+
with HDFStore(tmp_path / setup_path, mode="a") as store:
193192
store["a"] = Series(range(5))
194193
store.flush()
195194
store.flush(fsync=True)
@@ -316,8 +315,8 @@ def test_complibs(tmp_path, lvl, lib, request):
316315
@pytest.mark.skipif(
317316
not is_platform_little_endian(), reason="reason platform is not little endian"
318317
)
319-
def test_encoding(setup_path):
320-
with ensure_clean_store(setup_path) as store:
318+
def test_encoding(tmp_path, setup_path):
319+
with HDFStore(tmp_path / setup_path) as store:
321320
df = DataFrame({"A": "foo", "B": "bar"}, index=range(5))
322321
df.loc[2, "A"] = np.nan
323322
df.loc[3, "B"] = np.nan

pandas/tests/io/pytables/test_keys.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
pytestmark = [pytest.mark.single_cpu]
1414

1515

16-
def test_keys(tmp_path):
17-
path = tmp_path / "test_keys.h5"
18-
with HDFStore(path) as store:
16+
def test_keys(tmp_path, setup_path):
17+
with HDFStore(tmp_path / setup_path) as store:
1918
store["a"] = Series(
2019
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
2120
)
@@ -60,21 +59,20 @@ class Table3(tables.IsDescription):
6059
assert len(df.columns) == 1
6160

6261

63-
def test_keys_illegal_include_keyword_value(tmp_path):
64-
path = tmp_path / "test_keys_illegal_include_keyword_value.h5"
65-
with HDFStore(path) as store:
62+
def test_keys_illegal_include_keyword_value(tmp_path, setup_path):
63+
with HDFStore(tmp_path / setup_path) as store:
6664
with pytest.raises(
6765
ValueError,
6866
match="`include` should be either 'pandas' or 'native' but is 'illegal'",
6967
):
7068
store.keys(include="illegal")
7169

7270

73-
def test_keys_ignore_hdf_softlink(tmp_path):
71+
def test_keys_ignore_hdf_softlink(tmp_path, setup_path):
7472
# GH 20523
7573
# Puts a softlink into HDF file and rereads
76-
path = tmp_path / "test_keys_ignore_hdf_softlink.h5"
77-
with HDFStore(path) as store:
74+
75+
with HDFStore(tmp_path / setup_path) as store:
7876
df = DataFrame({"A": range(5), "B": range(5)})
7977
store.put("df", df)
8078

0 commit comments

Comments
 (0)