@@ -211,20 +211,10 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
211
211
else :
212
212
data = data .reindex (index , copy = copy )
213
213
data = data ._data
214
- elif isinstance (data , dict ) and (len (data ) or index is None ):
215
- # Include the len(data) check here, since _init_dict contains
216
- # a relatively expensive reindex. When called with
217
- # Series(data=None, index=idx`, that is unnescessary. We know
218
- # we're all NaN anyway, so we handle this in the next block.
219
- # https://github.com/pandas-dev/pandas/pull/18496/
214
+ elif isinstance (data , dict ):
220
215
data , index = self ._init_dict (data , index , dtype )
221
216
dtype = None
222
217
copy = False
223
- elif isinstance (data , dict ):
224
- # Same as previous block, but special cased for data=None,
225
- # for performance when creating empty arrays.
226
- data = na_value_for_dtype (dtype )
227
-
228
218
elif isinstance (data , SingleBlockManager ):
229
219
if index is None :
230
220
index = data .index
@@ -314,14 +304,19 @@ def _init_dict(self, data, index=None, dtype=None):
314
304
if data :
315
305
keys , values = zip (* compat .iteritems (data ))
316
306
values = list (values )
307
+ elif index is not None :
308
+ # fastpath for Series(data=None). Just use broadcasting a scalar
309
+ # instead of reindexing.
310
+ values = na_value_for_dtype (dtype )
311
+ keys = index
317
312
else :
318
313
keys , values = [], []
319
314
320
315
# Input is now list-like, so rely on "standard" construction:
321
316
s = Series (values , index = keys , dtype = dtype )
322
317
323
318
# Now we just make sure the order is respected, if any
324
- if index is not None :
319
+ if data and index is not None :
325
320
s = s .reindex (index , copy = False )
326
321
elif not PY36 and not isinstance (data , OrderedDict ):
327
322
try :
0 commit comments