2020import  pandas ._testing  as  tm 
2121from  pandas .tests .io .pytables .common  import  (
2222    _maybe_remove ,
23-     ensure_clean_store ,
2423)
2524
2625
@@ -46,7 +45,7 @@ def _compare_with_tz(a, b):
4645    "ignore:`alltrue` is deprecated as of NumPy 1.25.0:DeprecationWarning"  
4746) 
4847@pytest .mark .parametrize ("gettz" , [gettz_dateutil , gettz_pytz ]) 
49- def  test_append_with_timezones (setup_path , gettz ):
48+ def  test_append_with_timezones (tmp_path , gettz ):
5049    # as columns 
5150
5251    # Single-tzinfo, no DST transition 
@@ -86,7 +85,8 @@ def test_append_with_timezones(setup_path, gettz):
8685        index = range (5 ),
8786    )
8887
89-     with  ensure_clean_store (setup_path ) as  store :
88+     path  =  tmp_path  /  "test_append_with_timezones.h5" 
89+     with  pd .HDFStore (path ) as  store :
9090        _maybe_remove (store , "df_tz" )
9191        store .append ("df_tz" , df_est , data_columns = ["A" ])
9292        result  =  store ["df_tz" ]
@@ -131,15 +131,16 @@ def test_append_with_timezones(setup_path, gettz):
131131
132132
133133@pytest .mark .parametrize ("gettz" , [gettz_dateutil , gettz_pytz ]) 
134- def  test_append_with_timezones_as_index (setup_path , gettz ):
134+ def  test_append_with_timezones_as_index (tmp_path , gettz ):
135135    # GH#4098 example 
136136
137137    dti  =  date_range ("2000-1-1" , periods = 3 , freq = "h" , tz = gettz ("US/Eastern" ))
138138    dti  =  dti ._with_freq (None )  # freq doesn't round-trip 
139139
140140    df  =  DataFrame ({"A" : Series (range (3 ), index = dti )})
141141
142-     with  ensure_clean_store (setup_path ) as  store :
142+     path  =  tmp_path  /  "test_append_with_timezones_as_index.h5" 
143+     with  pd .HDFStore (path ) as  store :
143144        _maybe_remove (store , "df" )
144145        store .put ("df" , df )
145146        result  =  store .select ("df" )
@@ -151,13 +152,14 @@ def test_append_with_timezones_as_index(setup_path, gettz):
151152        tm .assert_frame_equal (result , df )
152153
153154
154- def  test_roundtrip_tz_aware_index (setup_path , unit ):
155+ def  test_roundtrip_tz_aware_index (tmp_path , unit ):
155156    # GH 17618 
156157    ts  =  Timestamp ("2000-01-01 01:00:00" , tz = "US/Eastern" )
157158    dti  =  DatetimeIndex ([ts ]).as_unit (unit )
158159    df  =  DataFrame (data = [0 ], index = dti )
159160
160-     with  ensure_clean_store (setup_path ) as  store :
161+     path  =  tmp_path  /  "test_roundtrip_tz_aware_index.h5" 
162+     with  pd .HDFStore (path ) as  store :
161163        store .put ("frame" , df , format = "fixed" )
162164        recons  =  store ["frame" ]
163165        tm .assert_frame_equal (recons , df )
@@ -167,20 +169,21 @@ def test_roundtrip_tz_aware_index(setup_path, unit):
167169    assert  value  ==  946706400000000000  //  denom 
168170
169171
170- def  test_store_index_name_with_tz (setup_path ):
172+ def  test_store_index_name_with_tz (tmp_path ):
171173    # GH 13884 
172174    df  =  DataFrame ({"A" : [1 , 2 ]})
173175    df .index  =  DatetimeIndex ([1234567890123456787 , 1234567890123456788 ])
174176    df .index  =  df .index .tz_localize ("UTC" )
175177    df .index .name  =  "foo" 
176178
177-     with  ensure_clean_store (setup_path ) as  store :
179+     path  =  tmp_path  /  "test_store_index_name_with_tz.h5" 
180+     with  pd .HDFStore (path ) as  store :
178181        store .put ("frame" , df , format = "table" )
179182        recons  =  store ["frame" ]
180183        tm .assert_frame_equal (recons , df )
181184
182185
183- def  test_tseries_select_index_column (setup_path ):
186+ def  test_tseries_select_index_column (tmp_path ):
184187    # GH7777 
185188    # selecting a UTC datetimeindex column did 
186189    # not preserve UTC tzinfo set before storing 
@@ -191,7 +194,8 @@ def test_tseries_select_index_column(setup_path):
191194        np .random .default_rng (2 ).standard_normal ((len (rng ), 4 )), index = rng 
192195    )
193196
194-     with  ensure_clean_store (setup_path ) as  store :
197+     path1  =  tmp_path  /  "test_tseries_select_index_column1.h5" 
198+     with  pd .HDFStore (path1 ) as  store :
195199        store .append ("frame" , frame )
196200        result  =  store .select_column ("frame" , "index" )
197201        assert  rng .tz  ==  DatetimeIndex (result .values ).tz 
@@ -202,7 +206,8 @@ def test_tseries_select_index_column(setup_path):
202206        np .random .default_rng (2 ).standard_normal ((len (rng ), 4 )), index = rng 
203207    )
204208
205-     with  ensure_clean_store (setup_path ) as  store :
209+     path2  =  tmp_path  /  "test_tseries_select_index_column2.h5" 
210+     with  pd .HDFStore (path2 ) as  store :
206211        store .append ("frame" , frame )
207212        result  =  store .select_column ("frame" , "index" )
208213        assert  rng .tz  ==  result .dt .tz 
@@ -213,14 +218,16 @@ def test_tseries_select_index_column(setup_path):
213218        np .random .default_rng (2 ).standard_normal ((len (rng ), 4 )), index = rng 
214219    )
215220
216-     with  ensure_clean_store (setup_path ) as  store :
221+     path3  =  tmp_path  /  "test_tseries_select_index_column3.h5" 
222+     with  pd .HDFStore (path3 ) as  store :
217223        store .append ("frame" , frame )
218224        result  =  store .select_column ("frame" , "index" )
219225        assert  rng .tz  ==  result .dt .tz 
220226
221227
222- def  test_timezones_fixed_format_frame_non_empty (setup_path ):
223-     with  ensure_clean_store (setup_path ) as  store :
228+ def  test_timezones_fixed_format_frame_non_empty (tmp_path ):
229+     path1  =  tmp_path  /  "test_timezones_fixed_format_frame_non_empty1.h5" 
230+     with  pd .HDFStore (path1 ) as  store :
224231        # index 
225232        rng  =  date_range ("1/1/2000" , "1/30/2000" , tz = "US/Eastern" )
226233        rng  =  rng ._with_freq (None )  # freq doesn't round-trip 
@@ -231,9 +238,12 @@ def test_timezones_fixed_format_frame_non_empty(setup_path):
231238        result  =  store ["df" ]
232239        tm .assert_frame_equal (result , df )
233240
234-         # as data 
235-         # GH11411 
236-         _maybe_remove (store , "df" )
241+     # as data 
242+     # GH11411 
243+     path2  =  tmp_path  /  "test_timezones_fixed_format_frame_non_empty2.h5" 
244+     with  pd .HDFStore (path2 ) as  store :
245+         rng  =  date_range ("1/1/2000" , "1/30/2000" , tz = "US/Eastern" )
246+         rng  =  rng ._with_freq (None )  # freq doesn't round-trip 
237247        df  =  DataFrame (
238248            {
239249                "A" : rng ,
@@ -243,12 +253,13 @@ def test_timezones_fixed_format_frame_non_empty(setup_path):
243253            },
244254            index = rng ,
245255        )
256+         _maybe_remove (store , "df" )
246257        store ["df" ] =  df 
247258        result  =  store ["df" ]
248259        tm .assert_frame_equal (result , df )
249260
250261
251- def  test_timezones_fixed_format_empty (setup_path , tz_aware_fixture , frame_or_series ):
262+ def  test_timezones_fixed_format_empty (tmp_path , tz_aware_fixture , frame_or_series ):
252263    # GH 20594 
253264
254265    dtype  =  pd .DatetimeTZDtype (tz = tz_aware_fixture )
@@ -257,53 +268,58 @@ def test_timezones_fixed_format_empty(setup_path, tz_aware_fixture, frame_or_ser
257268    if  frame_or_series  is  DataFrame :
258269        obj  =  obj .to_frame ()
259270
260-     with  ensure_clean_store (setup_path ) as  store :
271+     path  =  tmp_path  /  "test_timezones_fixed_format_empty.h5" 
272+     with  pd .HDFStore (path ) as  store :
261273        store ["obj" ] =  obj 
262274        result  =  store ["obj" ]
263275        tm .assert_equal (result , obj )
264276
265277
266- def  test_timezones_fixed_format_series_nonempty (setup_path , tz_aware_fixture ):
278+ def  test_timezones_fixed_format_series_nonempty (tmp_path , tz_aware_fixture ):
267279    # GH 20594 
268280
269281    dtype  =  pd .DatetimeTZDtype (tz = tz_aware_fixture )
270282
271-     with  ensure_clean_store (setup_path ) as  store :
283+     path  =  tmp_path  /  "test_timezones_fixed_format_series_nonempty.h5" 
284+     with  pd .HDFStore (path ) as  store :
272285        s  =  Series ([0 ], dtype = dtype )
273286        store ["s" ] =  s 
274287        result  =  store ["s" ]
275288        tm .assert_series_equal (result , s )
276289
277290
278- def  test_fixed_offset_tz (setup_path ):
291+ def  test_fixed_offset_tz (tmp_path ):
279292    rng  =  date_range ("1/1/2000 00:00:00-07:00" , "1/30/2000 00:00:00-07:00" )
280293    frame  =  DataFrame (
281294        np .random .default_rng (2 ).standard_normal ((len (rng ), 4 )), index = rng 
282295    )
283296
284-     with  ensure_clean_store (setup_path ) as  store :
297+     path  =  tmp_path  /  "test_fixed_offset_tz.h5" 
298+     with  pd .HDFStore (path ) as  store :
285299        store ["frame" ] =  frame 
286300        recons  =  store ["frame" ]
287301        tm .assert_index_equal (recons .index , rng )
288302        assert  rng .tz  ==  recons .index .tz 
289303
290304
291305@td .skip_if_windows  
292- def  test_store_timezone (setup_path ):
306+ def  test_store_timezone (tmp_path ):
293307    # GH2852 
294308    # issue storing datetime.date with a timezone as it resets when read 
295309    # back in a new timezone 
296310
297311    # original method 
298-     with  ensure_clean_store (setup_path ) as  store :
312+     path1  =  tmp_path  /  "test_store_timezone1.h5" 
313+     with  pd .HDFStore (path1 ) as  store :
299314        today  =  date (2013 , 9 , 10 )
300315        df  =  DataFrame ([1 , 2 , 3 ], index = [today , today , today ])
301316        store ["obj1" ] =  df 
302317        result  =  store ["obj1" ]
303318        tm .assert_frame_equal (result , df )
304319
305320    # with tz setting 
306-     with  ensure_clean_store (setup_path ) as  store :
321+     path2  =  tmp_path  /  "test_store_timezone2.h5" 
322+     with  pd .HDFStore (path2 ) as  store :
307323        with  tm .set_timezone ("EST5EDT" ):
308324            today  =  date (2013 , 9 , 10 )
309325            df  =  DataFrame ([1 , 2 , 3 ], index = [today , today , today ])
@@ -315,9 +331,10 @@ def test_store_timezone(setup_path):
315331        tm .assert_frame_equal (result , df )
316332
317333
318- def  test_dst_transitions (setup_path ):
334+ def  test_dst_transitions (tmp_path ):
319335    # make sure we are not failing on transitions 
320-     with  ensure_clean_store (setup_path ) as  store :
336+     path  =  tmp_path  /  "test_dst_transitions.h5" 
337+     with  pd .HDFStore (path ) as  store :
321338        times  =  date_range (
322339            "2013-10-26 23:00" ,
323340            "2013-10-27 01:00" ,
0 commit comments