Skip to content

"ValueError" on specific MultiIndex.from_product initialization(s?) #12258

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

Closed
toobaz opened this issue Feb 8, 2016 · 1 comment
Closed

"ValueError" on specific MultiIndex.from_product initialization(s?) #12258

toobaz opened this issue Feb 8, 2016 · 1 comment
Labels
Compat pandas objects compatability with Numpy or Python functions MultiIndex Testing pandas testing functions or related to the test suite
Milestone

Comments

@toobaz
Copy link
Member

toobaz commented Feb 8, 2016

Probably my favourite bug so far:

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.

@jreback
Copy link
Contributor

jreback commented Feb 8, 2016

I guess these should work. We don't appear to have any tests for empty level construction.

Note these are pretty much useless in practice.

@jreback jreback added Testing pandas testing functions or related to the test suite MultiIndex Compat pandas objects compatability with Numpy or Python functions Difficulty Intermediate labels Feb 8, 2016
@jreback jreback added this to the Next Major Release milestone Feb 8, 2016
@jreback jreback modified the milestones: 0.19.0, Next Major Release Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions MultiIndex Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants