New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: unique on an empty MI #20568

Closed
jreback opened this Issue Mar 31, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@jreback
Contributor

jreback commented Mar 31, 2018

In [13]: pd.MultiIndex.from_arrays([[], []])
Out[13]: 
MultiIndex(levels=[[], []],
           labels=[[], []])

In [14]: pd.MultiIndex.from_arrays([[], []]).unique()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-d5be3b23b8c3> in <module>()
----> 1 pd.MultiIndex.from_arrays([[], []]).unique()

~/pandas/pandas/core/indexes/multi.py in unique(self, level)
   1071 
   1072         if level is None:
-> 1073             return super(MultiIndex, self).unique()
   1074         else:
   1075             level = self._get_level_number(level)

~/pandas/pandas/core/indexes/base.py in unique(self, level)
   4366             self._validate_index_level(level)
   4367         result = super(Index, self).unique()
-> 4368         return self._shallow_copy(result)
   4369 
   4370     def drop_duplicates(self, keep='first'):

~/pandas/pandas/core/indexes/multi.py in _shallow_copy(self, values, **kwargs)
    558             # discards freq
    559             kwargs.pop('freq', None)
--> 560             return MultiIndex.from_tuples(values, **kwargs)
    561         return self.view()
    562 

~/pandas/pandas/core/indexes/multi.py in from_tuples(cls, tuples, sortorder, names)
   1315             if names is None:
   1316                 msg = 'Cannot infer number of levels from empty list'
-> 1317                 raise TypeError(msg)
   1318             arrays = [[]] * len(names)
   1319         elif isinstance(tuples, (np.ndarray, Index)):

TypeError: Cannot infer number of levels from empty list

@jreback

This comment has been minimized.

Contributor

jreback commented Mar 31, 2018

@toobaz

This comment has been minimized.

Member

toobaz commented Mar 31, 2018

Duplicate of #20308

@toobaz toobaz marked this as a duplicate of #20308 Mar 31, 2018

@toobaz toobaz closed this Mar 31, 2018

toobaz added a commit to toobaz/pandas that referenced this issue Mar 31, 2018

@toobaz toobaz referenced this issue Mar 31, 2018

Merged

BUG: .unique() on MultiIndex: preserve names #20571

5 of 5 tasks complete

toobaz added a commit to toobaz/pandas that referenced this issue Mar 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment