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