1818)
1919from pandas .tests .io .pytables .common import (
2020 _maybe_remove ,
21- ensure_clean_store ,
2221)
2322from pandas .util import _test_decorators as td
2423
@@ -46,7 +45,8 @@ def test_format_kwarg_in_constructor(tmp_path, setup_path):
4645
4746def 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,20 @@ 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 (
200+ tmp_path , setup_path , performance_warning , using_infer_string
201+ ):
196202 # https://github.com/pandas-dev/pandas/pull/60663
197203 ser = Series (3 * [Timestamp ("20010102" ).as_unit ("ns" )])
198- with ensure_clean_store (setup_path ) as store :
204+ path = tmp_path / setup_path
205+ with HDFStore (path ) as store :
199206 store .put ("ser" , ser )
200207 expected = ser .copy ()
201208 result = store .get ("ser" )
202209 tm .assert_series_equal (result , expected )
203210
204211
205- def test_put_mixed_type (setup_path , performance_warning , using_infer_string ):
212+ def test_put_mixed_type (tmp_path , setup_path , performance_warning , using_infer_string ):
206213 df = DataFrame (
207214 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
208215 columns = Index (list ("ABCD" )),
@@ -222,7 +229,8 @@ def test_put_mixed_type(setup_path, performance_warning, using_infer_string):
222229 df .loc [df .index [3 :6 ], ["obj1" ]] = np .nan
223230 df = df ._consolidate ()
224231
225- with ensure_clean_store (setup_path ) as store :
232+ path = tmp_path / setup_path
233+ with HDFStore (path ) as store :
226234 _maybe_remove (store , "df" )
227235
228236 warning = None if using_infer_string else performance_warning
@@ -233,11 +241,14 @@ def test_put_mixed_type(setup_path, performance_warning, using_infer_string):
233241 tm .assert_frame_equal (expected , df )
234242
235243
236- def test_put_str_frame (setup_path , performance_warning , string_dtype_arguments ):
244+ def test_put_str_frame (
245+ tmp_path , setup_path , performance_warning , string_dtype_arguments
246+ ):
237247 # https://github.com/pandas-dev/pandas/pull/60663
238248 dtype = pd .StringDtype (* string_dtype_arguments )
239249 df = DataFrame ({"a" : pd .array (["x" , pd .NA , "y" ], dtype = dtype )})
240- with ensure_clean_store (setup_path ) as store :
250+ path = tmp_path / setup_path
251+ with HDFStore (path ) as store :
241252 _maybe_remove (store , "df" )
242253
243254 store .put ("df" , df )
@@ -247,11 +258,14 @@ def test_put_str_frame(setup_path, performance_warning, string_dtype_arguments):
247258 tm .assert_frame_equal (result , expected )
248259
249260
250- def test_put_str_series (setup_path , performance_warning , string_dtype_arguments ):
261+ def test_put_str_series (
262+ tmp_path , setup_path , performance_warning , string_dtype_arguments
263+ ):
251264 # https://github.com/pandas-dev/pandas/pull/60663
252265 dtype = pd .StringDtype (* string_dtype_arguments )
253266 ser = Series (["x" , pd .NA , "y" ], dtype = dtype )
254- with ensure_clean_store (setup_path ) as store :
267+ path = tmp_path / setup_path
268+ with HDFStore (path ) as store :
255269 _maybe_remove (store , "df" )
256270
257271 store .put ("ser" , ser )
@@ -272,11 +286,12 @@ def test_put_str_series(setup_path, performance_warning, string_dtype_arguments)
272286 pd .period_range ("2020-01-01" , periods = 10 ),
273287 ],
274288)
275- def test_store_index_types (setup_path , format , index ):
289+ def test_store_index_types (tmp_path , setup_path , format , index ):
276290 # GH5386
277291 # test storing various index types
278292
279- with ensure_clean_store (setup_path ) as store :
293+ path = tmp_path / setup_path
294+ with HDFStore (path ) as store :
280295 df = DataFrame (
281296 np .random .default_rng (2 ).standard_normal ((10 , 2 )),
282297 columns = list ("AB" ),
@@ -287,7 +302,7 @@ def test_store_index_types(setup_path, format, index):
287302 tm .assert_frame_equal (df , store ["df" ])
288303
289304
290- def test_column_multiindex (setup_path , using_infer_string ):
305+ def test_column_multiindex (tmp_path , setup_path , using_infer_string ):
291306 # GH 4710
292307 # recreate multi-indexes properly
293308
@@ -297,7 +312,8 @@ def test_column_multiindex(setup_path, using_infer_string):
297312 df = DataFrame (np .arange (12 ).reshape (3 , 4 ), columns = index )
298313 expected = df .set_axis (df .index .to_numpy ())
299314
300- with ensure_clean_store (setup_path ) as store :
315+ path = tmp_path / setup_path
316+ with HDFStore (path ) as store :
301317 if using_infer_string :
302318 # TODO(infer_string) make this work for string dtype
303319 msg = "Saving a MultiIndex with an extension dtype is not supported."
@@ -322,7 +338,8 @@ def test_column_multiindex(setup_path, using_infer_string):
322338 store .put ("df3" , df , format = "table" , data_columns = True )
323339
324340 # appending multi-column on existing table (see GH 6167)
325- with ensure_clean_store (setup_path ) as store :
341+ path2 = tmp_path / "test2.h5"
342+ with HDFStore (path2 ) as store :
326343 store .append ("df2" , df )
327344 store .append ("df2" , df )
328345
@@ -332,17 +349,19 @@ def test_column_multiindex(setup_path, using_infer_string):
332349 df = DataFrame (np .arange (12 ).reshape (3 , 4 ), columns = Index (list ("ABCD" ), name = "foo" ))
333350 expected = df .set_axis (df .index .to_numpy ())
334351
335- with ensure_clean_store (setup_path ) as store :
352+ path3 = tmp_path / "test3.h5"
353+ with HDFStore (path3 ) as store :
336354 store .put ("df1" , df , format = "table" )
337355 tm .assert_frame_equal (
338356 store ["df1" ], expected , check_index_type = True , check_column_type = True
339357 )
340358
341359
342- def test_store_multiindex (setup_path ):
360+ def test_store_multiindex (tmp_path , setup_path ):
343361 # validate multi-index names
344362 # GH 5527
345- with ensure_clean_store (setup_path ) as store :
363+ path = tmp_path / setup_path
364+ with HDFStore (path ) as store :
346365
347366 def make_index (names = None ):
348367 dti = date_range ("2013-12-01" , "2013-12-02" )
0 commit comments