Skip to content

Commit d3d9f45

Browse files
committed
BUG: workaround for pandas-dev#18485
1 parent 143dcbf commit d3d9f45

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/core/series.py

+14
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,16 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
197197
data = data.reindex(index, copy=copy)
198198
data = data._data
199199
elif isinstance(data, dict):
200+
remap_to_mi = False
200201
if data:
201202
keys, values = zip(*compat.iteritems(data))
203+
# Workaround for #18485 - part 1/3
204+
maybe_mi_keys = Index(list(keys), tupleize_cols=True)
205+
if isinstance(maybe_mi_keys, MultiIndex):
206+
remap_to_mi = True
207+
keys = Index(list(keys), tupleize_cols=False)
208+
else:
209+
keys = maybe_mi_keys
202210
else:
203211
if index is None:
204212
index = Index([])
@@ -208,13 +216,19 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
208216
if index is not None:
209217
if not index.equals(s.index):
210218
s = s.reindex(index)
219+
# Workaround for #18485 - part 2/3
220+
remap_to_mi = False
211221
elif not isinstance(data, OrderedDict):
212222
try:
213223
s = s.sort_index()
214224
except TypeError:
215225
pass
216226
data = s._data
217227
index = s.index
228+
# Workaround for #18485 - part 3/3
229+
if remap_to_mi:
230+
index = Index(list(s.index), tupleize_cols=True)
231+
data.set_axis(0, index)
218232
copy = False
219233
dtype = None
220234
elif isinstance(data, SingleBlockManager):

0 commit comments

Comments
 (0)