33import numpy as np
44import pytest
55
6- from pandas ._config import using_string_dtype
7-
86from pandas .core .dtypes .base import _registry as ea_registry
97from pandas .core .dtypes .common import is_object_dtype
108from pandas .core .dtypes .dtypes import (
@@ -146,13 +144,16 @@ def test_setitem_different_dtype(self):
146144 )
147145 tm .assert_series_equal (result , expected )
148146
149- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
150147 def test_setitem_empty_columns (self ):
151148 # GH 13522
152149 df = DataFrame (index = ["A" , "B" , "C" ])
153150 df ["X" ] = df .index
154151 df ["X" ] = ["x" , "y" , "z" ]
155- exp = DataFrame (data = {"X" : ["x" , "y" , "z" ]}, index = ["A" , "B" , "C" ])
152+ exp = DataFrame (
153+ data = {"X" : ["x" , "y" , "z" ]},
154+ index = ["A" , "B" , "C" ],
155+ columns = Index (["X" ], dtype = object ),
156+ )
156157 tm .assert_frame_equal (df , exp )
157158
158159 def test_setitem_dt64_index_empty_columns (self ):
@@ -162,14 +163,15 @@ def test_setitem_dt64_index_empty_columns(self):
162163 df ["A" ] = rng
163164 assert df ["A" ].dtype == np .dtype ("M8[ns]" )
164165
165- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
166166 def test_setitem_timestamp_empty_columns (self ):
167167 # GH#19843
168168 df = DataFrame (index = range (3 ))
169169 df ["now" ] = Timestamp ("20130101" , tz = "UTC" )
170170
171171 expected = DataFrame (
172- [[Timestamp ("20130101" , tz = "UTC" )]] * 3 , index = range (3 ), columns = ["now" ]
172+ [[Timestamp ("20130101" , tz = "UTC" )]] * 3 ,
173+ index = range (3 ),
174+ columns = Index (["now" ], dtype = object ),
173175 )
174176 tm .assert_frame_equal (df , expected )
175177
@@ -202,14 +204,13 @@ def test_setitem_with_unaligned_sparse_value(self):
202204 expected = Series (SparseArray ([1 , 0 , 0 ]), name = "new_column" )
203205 tm .assert_series_equal (df ["new_column" ], expected )
204206
205- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
206207 def test_setitem_period_preserves_dtype (self ):
207208 # GH: 26861
208209 data = [Period ("2003-12" , "D" )]
209210 result = DataFrame ([])
210211 result ["a" ] = data
211212
212- expected = DataFrame ({"a" : data })
213+ expected = DataFrame ({"a" : data }, columns = Index ([ "a" ], dtype = object ) )
213214
214215 tm .assert_frame_equal (result , expected )
215216
@@ -672,11 +673,10 @@ def test_setitem_iloc_two_dimensional_generator(self):
672673 expected = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 1 , 1 ]})
673674 tm .assert_frame_equal (df , expected )
674675
675- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
676676 def test_setitem_dtypes_bytes_type_to_object (self ):
677677 # GH 20734
678678 index = Series (name = "id" , dtype = "S24" )
679- df = DataFrame (index = index )
679+ df = DataFrame (index = index , columns = Index ([], dtype = "str" ) )
680680 df ["a" ] = Series (name = "a" , index = index , dtype = np .uint32 )
681681 df ["b" ] = Series (name = "b" , index = index , dtype = "S64" )
682682 df ["c" ] = Series (name = "c" , index = index , dtype = "S64" )
@@ -705,7 +705,6 @@ def test_setitem_ea_dtype_rhs_series(self):
705705 expected = DataFrame ({"a" : [1 , 2 ]}, dtype = "Int64" )
706706 tm .assert_frame_equal (df , expected )
707707
708- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
709708 def test_setitem_npmatrix_2d (self ):
710709 # GH#42376
711710 # for use-case df["x"] = sparse.random((10, 10)).mean(axis=1)
@@ -714,7 +713,7 @@ def test_setitem_npmatrix_2d(self):
714713 )
715714
716715 a = np .ones ((10 , 1 ))
717- df = DataFrame (index = np .arange (10 ))
716+ df = DataFrame (index = np .arange (10 ), columns = Index ([], dtype = "str" ) )
718717 df ["np-array" ] = a
719718
720719 # Instantiation of `np.matrix` gives PendingDeprecationWarning
@@ -927,12 +926,11 @@ def test_setitem_with_expansion_categorical_dtype(self):
927926 ser .name = "E"
928927 tm .assert_series_equal (result2 .sort_index (), ser .sort_index ())
929928
930- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
931929 def test_setitem_scalars_no_index (self ):
932930 # GH#16823 / GH#17894
933931 df = DataFrame ()
934932 df ["foo" ] = 1
935- expected = DataFrame (columns = ["foo" ]).astype (np .int64 )
933+ expected = DataFrame (columns = Index ( ["foo" ], dtype = object ) ).astype (np .int64 )
936934 tm .assert_frame_equal (df , expected )
937935
938936 def test_setitem_newcol_tuple_key (self , float_frame ):
0 commit comments