36
36
37
37
pytestmark = [
38
38
pytest .mark .single_cpu ,
39
- pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False ),
40
39
]
41
40
42
41
43
42
@pytest .mark .parametrize ("mode" , ["r" , "r+" , "a" , "w" ])
44
- def test_mode (setup_path , tmp_path , mode ):
43
+ def test_mode (setup_path , tmp_path , mode , using_infer_string ):
45
44
df = DataFrame (
46
45
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
47
46
columns = Index (list ("ABCD" ), dtype = object ),
@@ -90,10 +89,12 @@ def test_mode(setup_path, tmp_path, mode):
90
89
read_hdf (path , "df" , mode = mode )
91
90
else :
92
91
result = read_hdf (path , "df" , mode = mode )
92
+ if using_infer_string :
93
+ df .columns = df .columns .astype ("str" )
93
94
tm .assert_frame_equal (result , df )
94
95
95
96
96
- def test_default_mode (tmp_path , setup_path ):
97
+ def test_default_mode (tmp_path , setup_path , using_infer_string ):
97
98
# read_hdf uses default mode
98
99
df = DataFrame (
99
100
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
@@ -103,7 +104,10 @@ def test_default_mode(tmp_path, setup_path):
103
104
path = tmp_path / setup_path
104
105
df .to_hdf (path , key = "df" , mode = "w" )
105
106
result = read_hdf (path , "df" )
106
- tm .assert_frame_equal (result , df )
107
+ expected = df .copy ()
108
+ if using_infer_string :
109
+ expected .columns = expected .columns .astype ("str" )
110
+ tm .assert_frame_equal (result , expected )
107
111
108
112
109
113
def test_reopen_handle (tmp_path , setup_path ):
@@ -162,7 +166,7 @@ def test_reopen_handle(tmp_path, setup_path):
162
166
assert not store .is_open
163
167
164
168
165
- def test_open_args (setup_path ):
169
+ def test_open_args (setup_path , using_infer_string ):
166
170
with tm .ensure_clean (setup_path ) as path :
167
171
df = DataFrame (
168
172
1.1 * np .arange (120 ).reshape ((30 , 4 )),
@@ -177,8 +181,13 @@ def test_open_args(setup_path):
177
181
store ["df" ] = df
178
182
store .append ("df2" , df )
179
183
180
- tm .assert_frame_equal (store ["df" ], df )
181
- tm .assert_frame_equal (store ["df2" ], df )
184
+ expected = df .copy ()
185
+ if using_infer_string :
186
+ expected .index = expected .index .astype ("str" )
187
+ expected .columns = expected .columns .astype ("str" )
188
+
189
+ tm .assert_frame_equal (store ["df" ], expected )
190
+ tm .assert_frame_equal (store ["df2" ], expected )
182
191
183
192
store .close ()
184
193
@@ -193,7 +202,7 @@ def test_flush(setup_path):
193
202
store .flush (fsync = True )
194
203
195
204
196
- def test_complibs_default_settings (tmp_path , setup_path ):
205
+ def test_complibs_default_settings (tmp_path , setup_path , using_infer_string ):
197
206
# GH15943
198
207
df = DataFrame (
199
208
1.1 * np .arange (120 ).reshape ((30 , 4 )),
@@ -206,7 +215,11 @@ def test_complibs_default_settings(tmp_path, setup_path):
206
215
tmpfile = tmp_path / setup_path
207
216
df .to_hdf (tmpfile , key = "df" , complevel = 9 )
208
217
result = read_hdf (tmpfile , "df" )
209
- tm .assert_frame_equal (result , df )
218
+ expected = df .copy ()
219
+ if using_infer_string :
220
+ expected .index = expected .index .astype ("str" )
221
+ expected .columns = expected .columns .astype ("str" )
222
+ tm .assert_frame_equal (result , expected )
210
223
211
224
with tables .open_file (tmpfile , mode = "r" ) as h5file :
212
225
for node in h5file .walk_nodes (where = "/df" , classname = "Leaf" ):
@@ -217,7 +230,11 @@ def test_complibs_default_settings(tmp_path, setup_path):
217
230
tmpfile = tmp_path / setup_path
218
231
df .to_hdf (tmpfile , key = "df" , complib = "zlib" )
219
232
result = read_hdf (tmpfile , "df" )
220
- tm .assert_frame_equal (result , df )
233
+ expected = df .copy ()
234
+ if using_infer_string :
235
+ expected .index = expected .index .astype ("str" )
236
+ expected .columns = expected .columns .astype ("str" )
237
+ tm .assert_frame_equal (result , expected )
221
238
222
239
with tables .open_file (tmpfile , mode = "r" ) as h5file :
223
240
for node in h5file .walk_nodes (where = "/df" , classname = "Leaf" ):
@@ -228,7 +245,11 @@ def test_complibs_default_settings(tmp_path, setup_path):
228
245
tmpfile = tmp_path / setup_path
229
246
df .to_hdf (tmpfile , key = "df" )
230
247
result = read_hdf (tmpfile , "df" )
231
- tm .assert_frame_equal (result , df )
248
+ expected = df .copy ()
249
+ if using_infer_string :
250
+ expected .index = expected .index .astype ("str" )
251
+ expected .columns = expected .columns .astype ("str" )
252
+ tm .assert_frame_equal (result , expected )
232
253
233
254
with tables .open_file (tmpfile , mode = "r" ) as h5file :
234
255
for node in h5file .walk_nodes (where = "/df" , classname = "Leaf" ):
@@ -302,6 +323,7 @@ def test_complibs(tmp_path, lvl, lib, request):
302
323
assert node .filters .complib == lib
303
324
304
325
326
+ @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
305
327
@pytest .mark .skipif (
306
328
not is_platform_little_endian (), reason = "reason platform is not little endian"
307
329
)
@@ -319,6 +341,7 @@ def test_encoding(setup_path):
319
341
tm .assert_frame_equal (result , expected )
320
342
321
343
344
+ @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
322
345
@pytest .mark .parametrize (
323
346
"val" ,
324
347
[
0 commit comments