@@ -137,6 +137,17 @@ def test_constructor_no_data_index_order(self):
137
137
result = pd .Series (index = ['b' , 'a' , 'c' ])
138
138
assert result .index .tolist () == ['b' , 'a' , 'c' ]
139
139
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
+
140
151
def test_constructor_series (self ):
141
152
index1 = ['d' , 'b' , 'a' , 'c' ]
142
153
index2 = sorted (index1 )
@@ -164,22 +175,25 @@ def test_constructor_list_like(self):
164
175
165
176
@pytest .mark .parametrize ('input_vals' , [
166
177
([1 , 2 ]),
167
- ([1.0 , 2.0 , np .nan ]),
168
178
(['1' , '2' ]),
169
179
(list (pd .date_range ('1/1/2011' , periods = 2 , freq = 'H' ))),
170
180
(list (pd .date_range ('1/1/2011' , periods = 2 , freq = 'H' ,
171
181
tz = 'US/Eastern' ))),
172
182
([pd .Interval (left = 0 , right = 5 )]),
173
183
])
174
- def test_constructor_list_str (self , input_vals ):
184
+ def test_constructor_list_str (self , input_vals , string_dtype ):
175
185
# GH 16605
176
186
# Ensure that data elements from a list are converted to strings
177
187
# 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 )
178
191
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 ])
183
197
184
198
def test_constructor_generator (self ):
185
199
gen = (i for i in range (10 ))
0 commit comments