Skip to content

Commit a60467d

Browse files
committed
Fix issue 18434
MultiIndex.from_tuples accept zipped tuples in python 3. Compatibility between 2 and 3.
1 parent fedc503 commit a60467d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

doc/source/whatsnew/v0.22.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Indexing
137137
- Bug in :func:`Series.truncate` which raises ``TypeError`` with a monotonic ``PeriodIndex`` (:issue:`17717`)
138138
- Bug in :func:`DataFrame.groupby` where tuples were interpreted as lists of keys rather than as keys (:issue:`17979`, :issue:`18249`)
139139
- Bug in :func:`MultiIndex.remove_unused_levels`` which would fill nan values (:issue:`18417`)
140+
- Bug in :func:`MultiIndex.from_tuples`` which would fail to take zipped tuples in python3 (:issue:`18434`)
140141
-
141142

142143
I/O

pandas/core/indexes/multi.py

+6
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,12 @@ def from_tuples(cls, tuples, sortorder=None, names=None):
12061206
MultiIndex.from_product : Make a MultiIndex from cartesian product
12071207
of iterables
12081208
"""
1209+
if not hasattr(tuples, '__len__'):
1210+
try:
1211+
iter(tuples) # if iterable, then it's iterator or generator
1212+
except TypeError:
1213+
raise TypeError('Inappropriate input for tuples.')
1214+
tuples = list(tuples)
12091215
if len(tuples) == 0:
12101216
if names is None:
12111217
msg = 'Cannot infer number of levels from empty list'

0 commit comments

Comments
 (0)