11
11
)
12
12
from pandas .tests .io .pytables .common import (
13
13
_maybe_remove ,
14
- ensure_clean_path ,
15
14
ensure_clean_store ,
16
15
)
17
16
@@ -147,7 +146,7 @@ def test_categorical(setup_path):
147
146
store .select ("df3/meta/s/meta" )
148
147
149
148
150
- def test_categorical_conversion (setup_path ):
149
+ def test_categorical_conversion (tmp_path , setup_path ):
151
150
152
151
# GH13322
153
152
# Check that read_hdf with categorical columns doesn't return rows if
@@ -161,24 +160,24 @@ def test_categorical_conversion(setup_path):
161
160
162
161
# We are expecting an empty DataFrame matching types of df
163
162
expected = df .iloc [[], :]
164
- with ensure_clean_path ( setup_path ) as path :
165
- df .to_hdf (path , "df" , format = "table" , data_columns = True )
166
- result = read_hdf (path , "df" , where = "obsids=B" )
167
- tm .assert_frame_equal (result , expected )
163
+ path = tmp_path / setup_path
164
+ df .to_hdf (path , "df" , format = "table" , data_columns = True )
165
+ result = read_hdf (path , "df" , where = "obsids=B" )
166
+ tm .assert_frame_equal (result , expected )
168
167
169
168
# Test with categories
170
169
df .obsids = df .obsids .astype ("category" )
171
170
df .imgids = df .imgids .astype ("category" )
172
171
173
172
# We are expecting an empty DataFrame matching types of df
174
173
expected = df .iloc [[], :]
175
- with ensure_clean_path ( setup_path ) as path :
176
- df .to_hdf (path , "df" , format = "table" , data_columns = True )
177
- result = read_hdf (path , "df" , where = "obsids=B" )
178
- tm .assert_frame_equal (result , expected )
174
+ path = tmp_path / setup_path
175
+ df .to_hdf (path , "df" , format = "table" , data_columns = True )
176
+ result = read_hdf (path , "df" , where = "obsids=B" )
177
+ tm .assert_frame_equal (result , expected )
179
178
180
179
181
- def test_categorical_nan_only_columns (setup_path ):
180
+ def test_categorical_nan_only_columns (tmp_path , setup_path ):
182
181
# GH18413
183
182
# Check that read_hdf with categorical columns with NaN-only values can
184
183
# be read back.
@@ -194,10 +193,10 @@ def test_categorical_nan_only_columns(setup_path):
194
193
df ["b" ] = df .b .astype ("category" )
195
194
df ["d" ] = df .b .astype ("category" )
196
195
expected = df
197
- with ensure_clean_path ( setup_path ) as path :
198
- df .to_hdf (path , "df" , format = "table" , data_columns = True )
199
- result = read_hdf (path , "df" )
200
- tm .assert_frame_equal (result , expected )
196
+ path = tmp_path / setup_path
197
+ df .to_hdf (path , "df" , format = "table" , data_columns = True )
198
+ result = read_hdf (path , "df" )
199
+ tm .assert_frame_equal (result , expected )
201
200
202
201
203
202
@pytest .mark .parametrize (
@@ -207,7 +206,9 @@ def test_categorical_nan_only_columns(setup_path):
207
206
('col=="a"' , DataFrame ({"col" : ["a" , "b" , "s" ]}), DataFrame ({"col" : ["a" ]})),
208
207
],
209
208
)
210
- def test_convert_value (setup_path , where : str , df : DataFrame , expected : DataFrame ):
209
+ def test_convert_value (
210
+ tmp_path , setup_path , where : str , df : DataFrame , expected : DataFrame
211
+ ):
211
212
# GH39420
212
213
# Check that read_hdf with categorical columns can filter by where condition.
213
214
df .col = df .col .astype ("category" )
@@ -216,7 +217,7 @@ def test_convert_value(setup_path, where: str, df: DataFrame, expected: DataFram
216
217
expected .col = expected .col .astype ("category" )
217
218
expected .col = expected .col .cat .set_categories (categorical_values )
218
219
219
- with ensure_clean_path ( setup_path ) as path :
220
- df .to_hdf (path , "df" , format = "table" , min_itemsize = max_widths )
221
- result = read_hdf (path , where = where )
222
- tm .assert_frame_equal (result , expected )
220
+ path = tmp_path / setup_path
221
+ df .to_hdf (path , "df" , format = "table" , min_itemsize = max_widths )
222
+ result = read_hdf (path , where = where )
223
+ tm .assert_frame_equal (result , expected )
0 commit comments