@@ -349,10 +349,18 @@ def test_integer_index_column(self):
349
349
df = pd .DataFrame ([(1 , 'a' ), (2 , 'b' ), (3 , 'c' )])
350
350
_check_pandas_roundtrip (df , preserve_index = True )
351
351
352
- def test_index_metadata_field_name (self , request ):
353
- if _pandas_api .uses_string_dtype ():
354
- # https://github.com/pandas-dev/pandas/issues/59879
355
- request .applymarker (pytest .mark .xfail (reason = "bug in pandas string dtype" ))
352
+ def test_float_column_index_with_missing (self ):
353
+ df = pd .DataFrame ([(1 , 'a' ), (2 , 'b' ), (3 , 'c' )], columns = [1.5 , np .nan ])
354
+ _check_pandas_roundtrip (df , preserve_index = True )
355
+
356
+ @pytest .mark .filterwarnings (
357
+ "ignore:The DataFrame has column names of mixed type:UserWarning"
358
+ )
359
+ def test_string_column_index_with_missing (self ):
360
+ df = pd .DataFrame ([(1 , 'a' ), (2 , 'b' ), (3 , 'c' )], columns = ["A" , None ])
361
+ _check_pandas_roundtrip (df , preserve_index = True )
362
+
363
+ def test_index_metadata_field_name (self ):
356
364
# test None case, and strangely named non-index columns
357
365
df = pd .DataFrame (
358
366
[(1 , 'a' , 3.1 ), (2 , 'b' , 2.2 ), (3 , 'c' , 1.3 )],
@@ -362,17 +370,24 @@ def test_index_metadata_field_name(self, request):
362
370
),
363
371
columns = ['a' , None , '__index_level_0__' ],
364
372
)
365
- with pytest . warns ( UserWarning ):
373
+ if _pandas_api . uses_string_dtype ( ):
366
374
t = pa .Table .from_pandas (df , preserve_index = True )
375
+ else :
376
+ with pytest .warns (UserWarning ):
377
+ t = pa .Table .from_pandas (df , preserve_index = True )
367
378
js = t .schema .pandas_metadata
368
379
369
380
col1 , col2 , col3 , idx0 , foo = js ['columns' ]
370
381
371
382
assert col1 ['name' ] == 'a'
372
383
assert col1 ['name' ] == col1 ['field_name' ]
373
384
374
- assert col2 ['name' ] is None
375
- assert col2 ['field_name' ] == 'None'
385
+ if _pandas_api .uses_string_dtype ():
386
+ assert np .isnan (col2 ['name' ])
387
+ assert col2 ['field_name' ] == 'nan'
388
+ else :
389
+ assert col2 ['name' ] is None
390
+ assert col2 ['field_name' ] == 'None'
376
391
377
392
assert col3 ['name' ] == '__index_level_0__'
378
393
assert col3 ['name' ] == col3 ['field_name' ]
0 commit comments