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