11import numpy as np
22import pytest
33
4- from pandas ._config import using_string_dtype
5-
64import pandas .util ._test_decorators as td
75
86from pandas import (
@@ -91,8 +89,6 @@ def test_fillna_datetime(self, datetime_frame):
9189 with pytest .raises (ValueError , match = msg ):
9290 datetime_frame .fillna (5 , method = "ffill" )
9391
94- # TODO(infer_string) test as actual error instead of xfail
95- @pytest .mark .xfail (using_string_dtype (), reason = "can't fill 0 in string" )
9692 def test_fillna_mixed_type (self , float_string_frame ):
9793 mf = float_string_frame
9894 mf .loc [mf .index [5 :20 ], "foo" ] = np .nan
@@ -126,7 +122,7 @@ def test_fillna_empty(self, using_copy_on_write):
126122 df .x .fillna (method = m , inplace = True )
127123 df .x .fillna (method = m )
128124
129- def test_fillna_different_dtype (self , using_infer_string ):
125+ def test_fillna_different_dtype (self ):
130126 # with different dtype (GH#3386)
131127 df = DataFrame (
132128 [["a" , "a" , np .nan , "a" ], ["b" , "b" , np .nan , "b" ], ["c" , "c" , np .nan , "c" ]]
@@ -136,6 +132,7 @@ def test_fillna_different_dtype(self, using_infer_string):
136132 expected = DataFrame (
137133 [["a" , "a" , "foo" , "a" ], ["b" , "b" , "foo" , "b" ], ["c" , "c" , "foo" , "c" ]]
138134 )
135+ # column is originally float (all-NaN) -> filling with string gives object dtype
139136 expected [2 ] = expected [2 ].astype ("object" )
140137 tm .assert_frame_equal (result , expected )
141138
@@ -654,18 +651,10 @@ def test_fillna_col_reordering(self):
654651 filled = df .fillna (method = "ffill" )
655652 assert df .columns .tolist () == filled .columns .tolist ()
656653
657- # TODO(infer_string) test as actual error instead of xfail
658- @pytest .mark .xfail (using_string_dtype (), reason = "can't fill 0 in string" )
659- def test_fill_corner (self , float_frame , float_string_frame ):
660- mf = float_string_frame
661- mf .loc [mf .index [5 :20 ], "foo" ] = np .nan
662- mf .loc [mf .index [- 10 :], "A" ] = np .nan
663-
664- filled = float_string_frame .fillna (value = 0 )
665- assert (filled .loc [filled .index [5 :20 ], "foo" ] == 0 ).all ()
666- del float_string_frame ["foo" ]
667-
668- float_frame .reindex (columns = []).fillna (value = 0 )
654+ def test_fill_empty (self , float_frame ):
655+ df = float_frame .reindex (columns = [])
656+ result = df .fillna (value = 0 )
657+ tm .assert_frame_equal (result , df )
669658
670659 def test_fillna_downcast_dict (self ):
671660 # GH#40809
0 commit comments