36
36
import pandas ._testing as tm
37
37
from pandas .tests .io .pytables .common import (
38
38
_maybe_remove ,
39
- create_tempfile ,
40
39
ensure_clean_path ,
41
40
ensure_clean_store ,
42
41
safe_close ,
43
- safe_remove ,
44
42
tables ,
45
43
)
46
44
@@ -80,33 +78,25 @@ def test_format_kwarg_in_constructor(self, setup_path):
80
78
81
79
msg = "format is not a defined argument for HDFStore"
82
80
83
- with ensure_clean_path (setup_path ) as path :
81
+ with tm . ensure_clean (setup_path ) as path :
84
82
with pytest .raises (ValueError , match = msg ):
85
83
HDFStore (path , format = "table" )
86
84
87
85
def test_context (self , setup_path ):
88
- path = create_tempfile (setup_path )
89
- try :
90
- with HDFStore (path ) as tbl :
91
- raise ValueError ("blah" )
92
- except ValueError :
93
- pass
94
- finally :
95
- safe_remove (path )
96
-
97
- try :
86
+ with tm .ensure_clean (setup_path ) as path :
87
+ try :
88
+ with HDFStore (path ) as tbl :
89
+ raise ValueError ("blah" )
90
+ except ValueError :
91
+ pass
92
+ with tm .ensure_clean (setup_path ) as path :
98
93
with HDFStore (path ) as tbl :
99
94
tbl ["a" ] = tm .makeDataFrame ()
100
-
101
- with HDFStore (path ) as tbl :
102
95
assert len (tbl ) == 1
103
96
assert type (tbl ["a" ]) == DataFrame
104
- finally :
105
- safe_remove (path )
106
97
107
98
def test_conv_read_write (self , setup_path ):
108
- path = create_tempfile (setup_path )
109
- try :
99
+ with tm .ensure_clean () as path :
110
100
111
101
def roundtrip (key , obj , ** kwargs ):
112
102
obj .to_hdf (path , key , ** kwargs )
@@ -127,9 +117,6 @@ def roundtrip(key, obj, **kwargs):
127
117
result = read_hdf (path , "table" , where = ["index>2" ])
128
118
tm .assert_frame_equal (df [df .index > 2 ], result )
129
119
130
- finally :
131
- safe_remove (path )
132
-
133
120
def test_long_strings (self , setup_path ):
134
121
135
122
# GH6166
@@ -605,7 +592,7 @@ def test_reopen_handle(self, setup_path):
605
592
606
593
def test_open_args (self , setup_path ):
607
594
608
- with ensure_clean_path (setup_path ) as path :
595
+ with tm . ensure_clean (setup_path ) as path :
609
596
610
597
df = tm .makeDataFrame ()
611
598
@@ -621,8 +608,8 @@ def test_open_args(self, setup_path):
621
608
622
609
store .close ()
623
610
624
- # the file should not have actually been written
625
- assert not os .path .exists (path )
611
+ # the file should not have actually been written
612
+ assert not os .path .exists (path )
626
613
627
614
def test_flush (self , setup_path ):
628
615
@@ -4194,7 +4181,6 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs):
4194
4181
import tempfile
4195
4182
4196
4183
fd , new_f = tempfile .mkstemp ()
4197
-
4198
4184
tstore = store .copy (
4199
4185
new_f , keys = keys , propindexes = propindexes , ** kwargs
4200
4186
)
@@ -4225,20 +4211,17 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs):
4225
4211
os .close (fd )
4226
4212
except (OSError , ValueError ):
4227
4213
pass
4228
- safe_remove (new_f )
4214
+ os . remove (new_f )
4229
4215
4230
4216
# new table
4231
4217
df = tm .makeDataFrame ()
4232
4218
4233
- try :
4234
- path = create_tempfile (setup_path )
4219
+ with tm .ensure_clean () as path :
4235
4220
st = HDFStore (path )
4236
4221
st .append ("df" , df , data_columns = ["A" ])
4237
4222
st .close ()
4238
4223
do_copy (f = path )
4239
4224
do_copy (f = path , propindexes = False )
4240
- finally :
4241
- safe_remove (path )
4242
4225
4243
4226
def test_store_datetime_fractional_secs (self , setup_path ):
4244
4227
@@ -4677,7 +4660,7 @@ def test_read_hdf_generic_buffer_errors(self):
4677
4660
4678
4661
def test_invalid_complib (self , setup_path ):
4679
4662
df = DataFrame (np .random .rand (4 , 5 ), index = list ("abcd" ), columns = list ("ABCDE" ))
4680
- with ensure_clean_path (setup_path ) as path :
4663
+ with tm . ensure_clean (setup_path ) as path :
4681
4664
with pytest .raises (ValueError ):
4682
4665
df .to_hdf (path , "df" , complib = "foolib" )
4683
4666
0 commit comments