@@ -5199,18 +5199,18 @@ def pytables_hdf5_file():
5199
5199
{'c0' : t0 + 3 , 'c1' : 'ddddd' , 'c2' : 4294967295 },
5200
5200
]
5201
5201
5202
- # This returns a path and does not open the file.
5203
- tmpfilepath = create_tempfile ( 'pytables_hdf5_file' )
5204
- objectname = 'pandas_test_timeseries'
5205
-
5206
- with tables .open_file (tmpfilepath , mode = 'w' ) as hf :
5207
- t = hf .create_table ('/' , name = objectname , description = table_schema )
5208
- for sample in testsamples :
5209
- for key , value in sample .items ():
5210
- t .row [key ] = value
5211
- t .row .append ()
5212
-
5213
- return tmpfilepath , objectname , pd .DataFrame (testsamples )
5202
+ objname = 'pandas_test_timeseries'
5203
+
5204
+ with ensure_clean_path ( 'pytables_hdf5_file' ) as path :
5205
+ # The `ensure_clean_path` context mgr removes the temp file upon exit.
5206
+ with tables .open_file (path , mode = 'w' ) as f :
5207
+ t = f .create_table ('/' , name = objname , description = table_schema )
5208
+ for sample in testsamples :
5209
+ for key , value in sample .items ():
5210
+ t .row [key ] = value
5211
+ t .row .append ()
5212
+
5213
+ yield path , objname , pd .DataFrame (testsamples )
5214
5214
5215
5215
5216
5216
class TestReadPyTablesHDF5 :
0 commit comments