Skip to content

Commit e51b274

Browse files
committed
fix for pandas-dev#60695 fix Series constructor dropping key levels when keys have varying entry counts
1 parent c71e898 commit e51b274

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pandas/core/indexes/multi.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,16 @@ def from_tuples(
567567
return cls.from_arrays(arrays, sortorder=sortorder, names=names)
568568

569569
# Convert to list and normalize
570-
tuples_list = list(tuples)
571-
max_length = max(len(t) if isinstance(t, tuple) else 1 for t in tuples_list)
572-
573-
result_tuples = []
574-
for t in tuples_list:
575-
if not isinstance(t, tuple):
576-
t = (t,)
577-
result_tuples.append(t + (np.nan,) * (max_length - len(t)))
578-
579-
arrays = list(lib.to_object_array_tuples(result_tuples).T)
570+
tuples_list = [t if isinstance(t, tuple) else (t,) for t in tuples]
571+
if not tuples_list:
572+
arrays = []
573+
else:
574+
max_length = max(len(t) for t in tuples_list)
575+
result_tuples = [
576+
t + (np.nan,) * (max_length - len(t)) for t in tuples_list
577+
]
578+
arrays = list(lib.to_object_array_tuples(result_tuples).T)
579+
580580
return cls.from_arrays(arrays, sortorder=sortorder, names=names)
581581

582582
@classmethod

0 commit comments

Comments
 (0)