@@ -137,6 +137,17 @@ def test_constructor_no_data_index_order(self):
137137 result = pd .Series (index = ['b' , 'a' , 'c' ])
138138 assert result .index .tolist () == ['b' , 'a' , 'c' ]
139139
140+ def test_constructor_dtype_str_na_values (self , string_dtype ):
141+ # https://github.com/pandas-dev/pandas/issues/21083
142+ ser = Series (['x' , None ], dtype = string_dtype )
143+ result = ser .isna ()
144+ expected = Series ([False , True ])
145+ tm .assert_series_equal (result , expected )
146+ assert ser .iloc [1 ] is None
147+
148+ ser = Series (['x' , np .nan ], dtype = string_dtype )
149+ assert np .isnan (ser .iloc [1 ])
150+
140151 def test_constructor_series (self ):
141152 index1 = ['d' , 'b' , 'a' , 'c' ]
142153 index2 = sorted (index1 )
@@ -164,22 +175,25 @@ def test_constructor_list_like(self):
164175
165176 @pytest .mark .parametrize ('input_vals' , [
166177 ([1 , 2 ]),
167- ([1.0 , 2.0 , np .nan ]),
168178 (['1' , '2' ]),
169179 (list (pd .date_range ('1/1/2011' , periods = 2 , freq = 'H' ))),
170180 (list (pd .date_range ('1/1/2011' , periods = 2 , freq = 'H' ,
171181 tz = 'US/Eastern' ))),
172182 ([pd .Interval (left = 0 , right = 5 )]),
173183 ])
174- def test_constructor_list_str (self , input_vals ):
184+ def test_constructor_list_str (self , input_vals , string_dtype ):
175185 # GH 16605
176186 # Ensure that data elements from a list are converted to strings
177187 # when dtype is str, 'str', or 'U'
188+ result = Series (input_vals , dtype = string_dtype )
189+ expected = Series (input_vals ).astype (string_dtype )
190+ assert_series_equal (result , expected )
178191
179- for dtype in ['str' , str , 'U' ]:
180- result = Series (input_vals , dtype = dtype )
181- expected = Series (input_vals ).astype (dtype )
182- assert_series_equal (result , expected )
192+ def test_constructor_list_str_na (self , string_dtype ):
193+ result = Series ([1.0 , 2.0 , np .nan ], dtype = string_dtype )
194+ expected = Series (['1.0' , '2.0' , np .nan ], dtype = object )
195+ assert_series_equal (result , expected )
196+ assert np .isnan (result [2 ])
183197
184198 def test_constructor_generator (self ):
185199 gen = (i for i in range (10 ))
0 commit comments