1111)
1212from pandas .tests .io .pytables .common import (
1313 _maybe_remove ,
14- ensure_clean_path ,
1514 ensure_clean_store ,
1615)
1716
@@ -147,7 +146,7 @@ def test_categorical(setup_path):
147146 store .select ("df3/meta/s/meta" )
148147
149148
150- def test_categorical_conversion (setup_path ):
149+ def test_categorical_conversion (tmp_path , setup_path ):
151150
152151 # GH13322
153152 # Check that read_hdf with categorical columns doesn't return rows if
@@ -161,24 +160,24 @@ def test_categorical_conversion(setup_path):
161160
162161 # We are expecting an empty DataFrame matching types of df
163162 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 )
168167
169168 # Test with categories
170169 df .obsids = df .obsids .astype ("category" )
171170 df .imgids = df .imgids .astype ("category" )
172171
173172 # We are expecting an empty DataFrame matching types of df
174173 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 )
179178
180179
181- def test_categorical_nan_only_columns (setup_path ):
180+ def test_categorical_nan_only_columns (tmp_path , setup_path ):
182181 # GH18413
183182 # Check that read_hdf with categorical columns with NaN-only values can
184183 # be read back.
@@ -194,10 +193,10 @@ def test_categorical_nan_only_columns(setup_path):
194193 df ["b" ] = df .b .astype ("category" )
195194 df ["d" ] = df .b .astype ("category" )
196195 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 )
201200
202201
203202@pytest .mark .parametrize (
@@ -207,7 +206,9 @@ def test_categorical_nan_only_columns(setup_path):
207206 ('col=="a"' , DataFrame ({"col" : ["a" , "b" , "s" ]}), DataFrame ({"col" : ["a" ]})),
208207 ],
209208)
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+ ):
211212 # GH39420
212213 # Check that read_hdf with categorical columns can filter by where condition.
213214 df .col = df .col .astype ("category" )
@@ -216,7 +217,7 @@ def test_convert_value(setup_path, where: str, df: DataFrame, expected: DataFram
216217 expected .col = expected .col .astype ("category" )
217218 expected .col = expected .col .cat .set_categories (categorical_values )
218219
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