"ValueError" on specific MultiIndex.from_product initialization(s?) · Issue #12258 · pandas-dev/pandas (original) (raw)

In [2]: pd.Series(index=pd.MultiIndex.from_product([[], [0,1], []], names=['var', 'per', 'extr']))
Out[2]: Series([], dtype: float64)

In [3]: pd.Series(index=pd.MultiIndex.from_product([[], [0,1,2,3], []], names=['var', 'per', 'extr']))
Out[3]: Series([], dtype: float64)

In [4]: pd.Series(index=pd.MultiIndex.from_product([[], [0,1,2], []], names=['var', 'per', 'extr']))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-82a0e40cf602> in <module>()
----> 1 pd.Series(index=pd.MultiIndex.from_product([[], [0,1,2], []], names=['var', 'per', 'extr']))

/home/nobackup/repo/pandas/pandas/indexes/multi.py in from_product(cls, iterables, sortorder, names)
    928         categoricals = [Categorical.from_array(it, ordered=True)
    929                         for it in iterables]
--> 930         labels = cartesian_product([c.codes for c in categoricals])
    931 
    932         return MultiIndex(levels=[c.categories for c in categoricals],

/home/nobackup/repo/pandas/pandas/tools/util.py in cartesian_product(X)
     37     return [np.tile(np.repeat(np.asarray(com._values_from_object(x)), b[i]),
     38                     np.product(a[i]))
---> 39             for i, x in enumerate(X)]
     40 
     41 

/home/nobackup/repo/pandas/pandas/tools/util.py in <listcomp>(.0)
     37     return [np.tile(np.repeat(np.asarray(com._values_from_object(x)), b[i]),
     38                     np.product(a[i]))
---> 39             for i, x in enumerate(X)]
     40 
     41 

/home/pietro/.local/lib/python3.4/site-packages/numpy/core/fromnumeric.py in repeat(a, repeats, axis)
    395     except AttributeError:
    396         return _wrapit(a, 'repeat', repeats, axis)
--> 397     return repeat(repeats, axis)
    398 
    399 

ValueError: negative dimensions are not allowed

This is with Python 3, doesn't happen with Python 2. I will try to investigate a bit later.