Skip to content

Commit 0988df1

Browse files
committed
Moved to init_dict
1 parent cf8c047 commit 0988df1

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

pandas/core/series.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,10 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
211211
else:
212212
data = data.reindex(index, copy=copy)
213213
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):
220215
data, index = self._init_dict(data, index, dtype)
221216
dtype = None
222217
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-
228218
elif isinstance(data, SingleBlockManager):
229219
if index is None:
230220
index = data.index
@@ -314,14 +304,19 @@ def _init_dict(self, data, index=None, dtype=None):
314304
if data:
315305
keys, values = zip(*compat.iteritems(data))
316306
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
317312
else:
318313
keys, values = [], []
319314

320315
# Input is now list-like, so rely on "standard" construction:
321316
s = Series(values, index=keys, dtype=dtype)
322317

323318
# 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:
325320
s = s.reindex(index, copy=False)
326321
elif not PY36 and not isinstance(data, OrderedDict):
327322
try:

0 commit comments

Comments
 (0)