Skip to content

Commit f8fa18d

Browse files
committed
Prevent 3D-ndarray for nested tuple labels (#24687)
1 parent fdc4db2 commit f8fa18d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pandas/core/indexes/base.py

+6
Original file line numberDiff line numberDiff line change
@@ -5282,6 +5282,12 @@ def ensure_index(index_like, copy=False):
52825282
if len(converted) > 0 and all_arrays:
52835283
from .multi import MultiIndex
52845284
return MultiIndex.from_arrays(converted)
5285+
elif converted.size > 2:
5286+
# When nested tuples are incorrectly converted
5287+
# to > 2 dimensions (Extremely rare)
5288+
index_like = np.ndarray((1, 2), dtype=tuple)
5289+
index_like[0][0] = tuple(converted[0][0])
5290+
index_like[0][1] = tuple(converted[0][1])
52855291
else:
52865292
index_like = converted
52875293
else:

0 commit comments

Comments
 (0)