Skip to content

Commit 0156542

Browse files
committed
TST: Replace ensure_clean_store with tmp_path in test_put.py
1 parent f4851e5 commit 0156542

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

pandas/tests/io/pytables/test_put.py

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
)
1919
from pandas.tests.io.pytables.common import (
2020
_maybe_remove,
21-
ensure_clean_store,
2221
)
2322
from pandas.util import _test_decorators as td
2423

@@ -46,7 +45,8 @@ def test_format_kwarg_in_constructor(tmp_path, setup_path):
4645

4746
def test_api_default_format(tmp_path, setup_path):
4847
# default_format option
49-
with ensure_clean_store(setup_path) as store:
48+
path = tmp_path / setup_path
49+
with HDFStore(path) as store:
5050
df = DataFrame(
5151
1.1 * np.arange(120).reshape((30, 4)),
5252
columns=Index(list("ABCD")),
@@ -94,8 +94,9 @@ def test_api_default_format(tmp_path, setup_path):
9494
assert store.get_storer("df4").is_table
9595

9696

97-
def test_put(setup_path):
98-
with ensure_clean_store(setup_path) as store:
97+
def test_put(tmp_path, setup_path):
98+
path = tmp_path / setup_path
99+
with HDFStore(path) as store:
99100
ts = Series(
100101
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
101102
)
@@ -131,8 +132,9 @@ def test_put(setup_path):
131132
tm.assert_frame_equal(df[:10], store["c"])
132133

133134

134-
def test_put_string_index(setup_path):
135-
with ensure_clean_store(setup_path) as store:
135+
def test_put_string_index(tmp_path, setup_path):
136+
path = tmp_path / setup_path
137+
with HDFStore(path) as store:
136138
index = Index([f"I am a very long string index: {i}" for i in range(20)])
137139
s = Series(np.arange(20), index=index)
138140
df = DataFrame({"A": s, "B": s})
@@ -157,8 +159,9 @@ def test_put_string_index(setup_path):
157159
tm.assert_frame_equal(store["b"], df)
158160

159161

160-
def test_put_compression(setup_path):
161-
with ensure_clean_store(setup_path) as store:
162+
def test_put_compression(tmp_path, setup_path):
163+
path = tmp_path / setup_path
164+
with HDFStore(path) as store:
162165
df = DataFrame(
163166
np.random.default_rng(2).standard_normal((10, 4)),
164167
columns=Index(list("ABCD")),
@@ -175,14 +178,15 @@ def test_put_compression(setup_path):
175178

176179

177180
@td.skip_if_windows
178-
def test_put_compression_blosc(setup_path):
181+
def test_put_compression_blosc(tmp_path, setup_path):
179182
df = DataFrame(
180183
np.random.default_rng(2).standard_normal((10, 4)),
181184
columns=Index(list("ABCD")),
182185
index=date_range("2000-01-01", periods=10, freq="B"),
183186
)
184187

185-
with ensure_clean_store(setup_path) as store:
188+
path = tmp_path / setup_path
189+
with HDFStore(path) as store:
186190
# can't compress if format='fixed'
187191
msg = "Compression not supported on Fixed format stores"
188192
with pytest.raises(ValueError, match=msg):
@@ -192,17 +196,18 @@ def test_put_compression_blosc(setup_path):
192196
tm.assert_frame_equal(store["c"], df)
193197

194198

195-
def test_put_datetime_ser(setup_path, performance_warning, using_infer_string):
199+
def test_put_datetime_ser(tmp_path, setup_path, performance_warning, using_infer_string):
196200
# https://github.com/pandas-dev/pandas/pull/60663
197201
ser = Series(3 * [Timestamp("20010102").as_unit("ns")])
198-
with ensure_clean_store(setup_path) as store:
202+
path = tmp_path / setup_path
203+
with HDFStore(path) as store:
199204
store.put("ser", ser)
200205
expected = ser.copy()
201206
result = store.get("ser")
202207
tm.assert_series_equal(result, expected)
203208

204209

205-
def test_put_mixed_type(setup_path, performance_warning, using_infer_string):
210+
def test_put_mixed_type(tmp_path, setup_path, performance_warning, using_infer_string):
206211
df = DataFrame(
207212
np.random.default_rng(2).standard_normal((10, 4)),
208213
columns=Index(list("ABCD")),
@@ -222,7 +227,8 @@ def test_put_mixed_type(setup_path, performance_warning, using_infer_string):
222227
df.loc[df.index[3:6], ["obj1"]] = np.nan
223228
df = df._consolidate()
224229

225-
with ensure_clean_store(setup_path) as store:
230+
path = tmp_path / setup_path
231+
with HDFStore(path) as store:
226232
_maybe_remove(store, "df")
227233

228234
warning = None if using_infer_string else performance_warning
@@ -233,11 +239,12 @@ def test_put_mixed_type(setup_path, performance_warning, using_infer_string):
233239
tm.assert_frame_equal(expected, df)
234240

235241

236-
def test_put_str_frame(setup_path, performance_warning, string_dtype_arguments):
242+
def test_put_str_frame(tmp_path, setup_path, performance_warning, string_dtype_arguments):
237243
# https://github.com/pandas-dev/pandas/pull/60663
238244
dtype = pd.StringDtype(*string_dtype_arguments)
239245
df = DataFrame({"a": pd.array(["x", pd.NA, "y"], dtype=dtype)})
240-
with ensure_clean_store(setup_path) as store:
246+
path = tmp_path / setup_path
247+
with HDFStore(path) as store:
241248
_maybe_remove(store, "df")
242249

243250
store.put("df", df)
@@ -247,11 +254,12 @@ def test_put_str_frame(setup_path, performance_warning, string_dtype_arguments):
247254
tm.assert_frame_equal(result, expected)
248255

249256

250-
def test_put_str_series(setup_path, performance_warning, string_dtype_arguments):
257+
def test_put_str_series(tmp_path, setup_path, performance_warning, string_dtype_arguments):
251258
# https://github.com/pandas-dev/pandas/pull/60663
252259
dtype = pd.StringDtype(*string_dtype_arguments)
253260
ser = Series(["x", pd.NA, "y"], dtype=dtype)
254-
with ensure_clean_store(setup_path) as store:
261+
path = tmp_path / setup_path
262+
with HDFStore(path) as store:
255263
_maybe_remove(store, "df")
256264

257265
store.put("ser", ser)
@@ -272,11 +280,12 @@ def test_put_str_series(setup_path, performance_warning, string_dtype_arguments)
272280
pd.period_range("2020-01-01", periods=10),
273281
],
274282
)
275-
def test_store_index_types(setup_path, format, index):
283+
def test_store_index_types(tmp_path, setup_path, format, index):
276284
# GH5386
277285
# test storing various index types
278286

279-
with ensure_clean_store(setup_path) as store:
287+
path = tmp_path / setup_path
288+
with HDFStore(path) as store:
280289
df = DataFrame(
281290
np.random.default_rng(2).standard_normal((10, 2)),
282291
columns=list("AB"),
@@ -287,7 +296,7 @@ def test_store_index_types(setup_path, format, index):
287296
tm.assert_frame_equal(df, store["df"])
288297

289298

290-
def test_column_multiindex(setup_path, using_infer_string):
299+
def test_column_multiindex(tmp_path, setup_path, using_infer_string):
291300
# GH 4710
292301
# recreate multi-indexes properly
293302

@@ -297,7 +306,8 @@ def test_column_multiindex(setup_path, using_infer_string):
297306
df = DataFrame(np.arange(12).reshape(3, 4), columns=index)
298307
expected = df.set_axis(df.index.to_numpy())
299308

300-
with ensure_clean_store(setup_path) as store:
309+
path = tmp_path / setup_path
310+
with HDFStore(path) as store:
301311
if using_infer_string:
302312
# TODO(infer_string) make this work for string dtype
303313
msg = "Saving a MultiIndex with an extension dtype is not supported."
@@ -322,7 +332,8 @@ def test_column_multiindex(setup_path, using_infer_string):
322332
store.put("df3", df, format="table", data_columns=True)
323333

324334
# appending multi-column on existing table (see GH 6167)
325-
with ensure_clean_store(setup_path) as store:
335+
path2 = tmp_path / "test2.h5"
336+
with HDFStore(path2) as store:
326337
store.append("df2", df)
327338
store.append("df2", df)
328339

@@ -332,17 +343,19 @@ def test_column_multiindex(setup_path, using_infer_string):
332343
df = DataFrame(np.arange(12).reshape(3, 4), columns=Index(list("ABCD"), name="foo"))
333344
expected = df.set_axis(df.index.to_numpy())
334345

335-
with ensure_clean_store(setup_path) as store:
346+
path3 = tmp_path / "test3.h5"
347+
with HDFStore(path3) as store:
336348
store.put("df1", df, format="table")
337349
tm.assert_frame_equal(
338350
store["df1"], expected, check_index_type=True, check_column_type=True
339351
)
340352

341353

342-
def test_store_multiindex(setup_path):
354+
def test_store_multiindex(tmp_path, setup_path):
343355
# validate multi-index names
344356
# GH 5527
345-
with ensure_clean_store(setup_path) as store:
357+
path = tmp_path / setup_path
358+
with HDFStore(path) as store:
346359

347360
def make_index(names=None):
348361
dti = date_range("2013-12-01", "2013-12-02")

0 commit comments

Comments
 (0)