Skip to content

Commit b10b0ce

Browse files
committed
BUG: workaround for pandas-dev#18485
1 parent f53613f commit b10b0ce

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,6 +216,8 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
208216
if index is not None:
209217
if not index.identical(s.index):
210218
s = s.reindex(index)
219+
# Workaround for #18485 - part 2/3
220+
remap_to_mi = False
211221
else:
212222
if not isinstance(data, OrderedDict):
213223
try:
@@ -216,6 +226,10 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
216226
pass
217227
index = s.index
218228
data = s._data
229+
# Workaround for #18485 - part 3/3
230+
if remap_to_mi:
231+
index = Index(list(s.index), tupleize_cols=True)
232+
data.set_axis(0, index)
219233
copy = False
220234
dtype = None
221235
elif isinstance(data, SingleBlockManager):

0 commit comments

Comments
 (0)