33import numpy as np
44import pytest
55
6- from pandas ._config import using_string_dtype
7-
86import pandas .util ._test_decorators as td
97
108from pandas .core .dtypes .base import _registry as ea_registry
@@ -148,13 +146,16 @@ def test_setitem_different_dtype(self):
148146 )
149147 tm .assert_series_equal (result , expected )
150148
151- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
152149 def test_setitem_empty_columns (self ):
153150 # GH 13522
154151 df = DataFrame (index = ["A" , "B" , "C" ])
155152 df ["X" ] = df .index
156153 df ["X" ] = ["x" , "y" , "z" ]
157- exp = DataFrame (data = {"X" : ["x" , "y" , "z" ]}, index = ["A" , "B" , "C" ])
154+ exp = DataFrame (
155+ data = {"X" : ["x" , "y" , "z" ]},
156+ index = ["A" , "B" , "C" ],
157+ columns = Index (["X" ], dtype = object ),
158+ )
158159 tm .assert_frame_equal (df , exp )
159160
160161 def test_setitem_dt64_index_empty_columns (self ):
@@ -164,14 +165,15 @@ def test_setitem_dt64_index_empty_columns(self):
164165 df ["A" ] = rng
165166 assert df ["A" ].dtype == np .dtype ("M8[ns]" )
166167
167- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
168168 def test_setitem_timestamp_empty_columns (self ):
169169 # GH#19843
170170 df = DataFrame (index = range (3 ))
171171 df ["now" ] = Timestamp ("20130101" , tz = "UTC" ).as_unit ("ns" )
172172
173173 expected = DataFrame (
174- [[Timestamp ("20130101" , tz = "UTC" )]] * 3 , index = [0 , 1 , 2 ], columns = ["now" ]
174+ [[Timestamp ("20130101" , tz = "UTC" )]] * 3 ,
175+ index = range (3 ),
176+ columns = Index (["now" ], dtype = object ),
175177 )
176178 tm .assert_frame_equal (df , expected )
177179
@@ -204,14 +206,13 @@ def test_setitem_with_unaligned_sparse_value(self):
204206 expected = Series (SparseArray ([1 , 0 , 0 ]), name = "new_column" )
205207 tm .assert_series_equal (df ["new_column" ], expected )
206208
207- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
208209 def test_setitem_period_preserves_dtype (self ):
209210 # GH: 26861
210211 data = [Period ("2003-12" , "D" )]
211212 result = DataFrame ([])
212213 result ["a" ] = data
213214
214- expected = DataFrame ({"a" : data })
215+ expected = DataFrame ({"a" : data }, columns = Index ([ "a" ], dtype = object ) )
215216
216217 tm .assert_frame_equal (result , expected )
217218
@@ -677,11 +678,10 @@ def test_setitem_iloc_two_dimensional_generator(self):
677678 expected = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 1 , 1 ]})
678679 tm .assert_frame_equal (df , expected )
679680
680- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
681681 def test_setitem_dtypes_bytes_type_to_object (self ):
682682 # GH 20734
683683 index = Series (name = "id" , dtype = "S24" )
684- df = DataFrame (index = index )
684+ df = DataFrame (index = index , columns = Index ([], dtype = "str" ) )
685685 df ["a" ] = Series (name = "a" , index = index , dtype = np .uint32 )
686686 df ["b" ] = Series (name = "b" , index = index , dtype = "S64" )
687687 df ["c" ] = Series (name = "c" , index = index , dtype = "S64" )
@@ -712,7 +712,6 @@ def test_setitem_ea_dtype_rhs_series(self):
712712
713713 # TODO(ArrayManager) set column with 2d column array, see #44788
714714 @td .skip_array_manager_not_yet_implemented
715- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
716715 def test_setitem_npmatrix_2d (self ):
717716 # GH#42376
718717 # for use-case df["x"] = sparse.random((10, 10)).mean(axis=1)
@@ -721,7 +720,7 @@ def test_setitem_npmatrix_2d(self):
721720 )
722721
723722 a = np .ones ((10 , 1 ))
724- df = DataFrame (index = np .arange (10 ))
723+ df = DataFrame (index = np .arange (10 ), columns = Index ([], dtype = "str" ) )
725724 df ["np-array" ] = a
726725
727726 # Instantiation of `np.matrix` gives PendingDeprecationWarning
@@ -936,12 +935,11 @@ def test_setitem_with_expansion_categorical_dtype(self):
936935 ser .name = "E"
937936 tm .assert_series_equal (result2 .sort_index (), ser .sort_index ())
938937
939- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
940938 def test_setitem_scalars_no_index (self ):
941939 # GH#16823 / GH#17894
942940 df = DataFrame ()
943941 df ["foo" ] = 1
944- expected = DataFrame (columns = ["foo" ]).astype (np .int64 )
942+ expected = DataFrame (columns = Index ( ["foo" ], dtype = object ) ).astype (np .int64 )
945943 tm .assert_frame_equal (df , expected )
946944
947945 def test_setitem_newcol_tuple_key (self , float_frame ):
0 commit comments