88import numpy as np
99import pytest
1010
11- from pandas ._config import using_string_dtype
12-
13- from pandas .compat import HAS_PYARROW
1411from pandas .compat .numpy import (
1512 np_version_gt2 ,
1613 np_version_gte1p24 ,
3734 concat ,
3835 date_range ,
3936 interval_range ,
37+ isna ,
4038 period_range ,
4139 timedelta_range ,
4240)
@@ -564,14 +562,16 @@ def test_append_timedelta_does_not_cast(self, td, using_infer_string, request):
564562 tm .assert_series_equal (ser , expected )
565563 assert isinstance (ser ["td" ], Timedelta )
566564
567- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
568565 def test_setitem_with_expansion_type_promotion (self ):
569566 # GH#12599
570567 ser = Series (dtype = object )
571568 ser ["a" ] = Timestamp ("2016-01-01" )
572569 ser ["b" ] = 3.0
573570 ser ["c" ] = "foo"
574- expected = Series ([Timestamp ("2016-01-01" ), 3.0 , "foo" ], index = ["a" , "b" , "c" ])
571+ expected = Series (
572+ [Timestamp ("2016-01-01" ), 3.0 , "foo" ],
573+ index = Index (["a" , "b" , "c" ], dtype = object ),
574+ )
575575 tm .assert_series_equal (ser , expected )
576576
577577 def test_setitem_not_contained (self , string_series ):
@@ -850,11 +850,6 @@ def test_mask_key(self, obj, key, expected, warn, val, indexer_sli):
850850 indexer_sli (obj )[mask ] = val
851851 tm .assert_series_equal (obj , expected )
852852
853- @pytest .mark .xfail (
854- using_string_dtype () and not HAS_PYARROW ,
855- reason = "TODO(infer_string)" ,
856- strict = False ,
857- )
858853 def test_series_where (self , obj , key , expected , warn , val , is_inplace ):
859854 mask = np .zeros (obj .shape , dtype = bool )
860855 mask [key ] = True
@@ -870,6 +865,11 @@ def test_series_where(self, obj, key, expected, warn, val, is_inplace):
870865 obj = obj .copy ()
871866 arr = obj ._values
872867
868+ if obj .dtype == "string" and not (isinstance (val , str ) or isna (val )):
869+ with pytest .raises (TypeError , match = "Invalid value" ):
870+ obj .where (~ mask , val )
871+ return
872+
873873 res = obj .where (~ mask , val )
874874
875875 if val is NA and res .dtype == object :
@@ -882,29 +882,27 @@ def test_series_where(self, obj, key, expected, warn, val, is_inplace):
882882
883883 self ._check_inplace (is_inplace , orig , arr , obj )
884884
885- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
886- def test_index_where (self , obj , key , expected , warn , val , using_infer_string ):
885+ def test_index_where (self , obj , key , expected , warn , val ):
887886 mask = np .zeros (obj .shape , dtype = bool )
888887 mask [key ] = True
889888
890- if using_infer_string and obj .dtype == object :
889+ if obj .dtype == "string" and not ( isinstance ( val , str ) or isna ( val )) :
891890 with pytest .raises (TypeError , match = "Invalid value" ):
892- Index (obj ).where (~ mask , val )
891+ Index (obj , dtype = obj . dtype ).where (~ mask , val )
893892 else :
894- res = Index (obj ).where (~ mask , val )
893+ res = Index (obj , dtype = obj . dtype ).where (~ mask , val )
895894 expected_idx = Index (expected , dtype = expected .dtype )
896895 tm .assert_index_equal (res , expected_idx )
897896
898- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
899- def test_index_putmask (self , obj , key , expected , warn , val , using_infer_string ):
897+ def test_index_putmask (self , obj , key , expected , warn , val ):
900898 mask = np .zeros (obj .shape , dtype = bool )
901899 mask [key ] = True
902900
903- if using_infer_string and obj .dtype == object :
901+ if obj .dtype == "string" and not ( isinstance ( val , str ) or isna ( val )) :
904902 with pytest .raises (TypeError , match = "Invalid value" ):
905- Index (obj ).putmask (mask , val )
903+ Index (obj , dtype = obj . dtype ).putmask (mask , val )
906904 else :
907- res = Index (obj ).putmask (mask , val )
905+ res = Index (obj , dtype = obj . dtype ).putmask (mask , val )
908906 tm .assert_index_equal (res , Index (expected , dtype = expected .dtype ))
909907
910908
0 commit comments