Skip to content

Commit

Permalink
Fix issue 18434
Browse files Browse the repository at this point in the history
MultiIndex.from_tuples accept zipped tuples in python 3. Compatibility
between 2 and 3.
  • Loading branch information
Xbar committed Nov 23, 2017
1 parent fedc503 commit a60467d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.22.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Indexing
- Bug in :func:`Series.truncate` which raises ``TypeError`` with a monotonic ``PeriodIndex`` (:issue:`17717`)
- Bug in :func:`DataFrame.groupby` where tuples were interpreted as lists of keys rather than as keys (:issue:`17979`, :issue:`18249`)
- Bug in :func:`MultiIndex.remove_unused_levels`` which would fill nan values (:issue:`18417`)
- Bug in :func:`MultiIndex.from_tuples`` which would fail to take zipped tuples in python3 (:issue:`18434`)
-

I/O
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,12 @@ def from_tuples(cls, tuples, sortorder=None, names=None):
MultiIndex.from_product : Make a MultiIndex from cartesian product
of iterables
"""
if not hasattr(tuples, '__len__'):
try:
iter(tuples) # if iterable, then it's iterator or generator
except TypeError:
raise TypeError('Inappropriate input for tuples.')
tuples = list(tuples)
if len(tuples) == 0:
if names is None:
msg = 'Cannot infer number of levels from empty list'
Expand Down

0 comments on commit a60467d

Please sign in to comment.