Skip to content

Commit d8b1312

Browse files
committed
More special cases
1 parent 0988df1 commit d8b1312

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/core/series.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ def _init_dict(self, data, index=None, dtype=None):
318318
# Now we just make sure the order is respected, if any
319319
if data and index is not None:
320320
s = s.reindex(index, copy=False)
321-
elif not PY36 and not isinstance(data, OrderedDict):
321+
elif not PY36 and not isinstance(data, OrderedDict) and data:
322+
# Need the `and data` to avoid sorting Series(None, index=[...])
323+
# since that isn't really dict-like
322324
try:
323325
s = s.sort_index()
324326
except TypeError:

pandas/tests/series/test_constructors.py

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def test_constructor_dtype_only(self, dtype, index):
133133
assert result.dtype == dtype
134134
assert len(result) == 0
135135

136+
def test_constructor_no_data_index_order(self):
137+
result = pd.Series(index=['b', 'a', 'c'])
138+
assert result.index.tolist() == ['b', 'a', 'c']
139+
136140
def test_constructor_series(self):
137141
index1 = ['d', 'b', 'a', 'c']
138142
index2 = sorted(index1)

0 commit comments

Comments
 (0)