Skip to content
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 in repeat() method with MultiIndex - fixed in 0.15 #9361

Closed
glyg opened this issue Jan 27, 2015 · 4 comments
Closed

bug in repeat() method with MultiIndex - fixed in 0.15 #9361

glyg opened this issue Jan 27, 2015 · 4 comments
Labels
Testing pandas testing functions or related to the test suite
Milestone

Comments

@glyg
Copy link
Contributor

glyg commented Jan 27, 2015

Hi,

I found a bug in version 0.14, which has since been fixed in 0.15. I thought I'd report it because I couldn't find a mention of it and it might have been fixed silently. Also I couldn't find a specific test for this bug (as far as I could see).

Here is a test that fails with the bug:

import pandas as pd
print(pd.version.version)

def test_multiindex_repeat():
    idx = pd.Index([1, 2, 3, 4])
    m_idx = pd.MultiIndex.from_tuples([(1, 2), (3, 4),
                                       (5, 6), (7, 8)])
    data = ['a', 'b', 'c', 'd']

    df = pd.Series(data, index=idx)
    m_df = pd.Series(data, index=m_idx)

    assert df.repeat(3).shape == (3 * len(data),)
    assert m_df.repeat(3).shape == (3 * len(data),)

test_multiindex_repeat()

With pandas 0.14, here is the backtrace:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-7fcd65f0e025> in <module>()
----> 1 assert m_df.repeat(3).shape == (3 * len(data),)

/home/guillaume/anaconda/envs/pelican/lib/python2.7/site-packages/pandas/core/series.pyc in repeat(self, reps)
    705         new_values = self.values.repeat(reps)
    706         return self._constructor(new_values,
--> 707                                  index=new_index).__finalize__(self)
    708 
    709     def reshape(self, *args, **kwargs):

/home/guillaume/anaconda/envs/pelican/lib/python2.7/site-packages/pandas/core/series.pyc in __init__(self, data, index, dtype, name, copy, fastpath)
    229                                        raise_cast_failure=True)
    230 
--> 231                 data = SingleBlockManager(data, index, fastpath=True)
    232 
    233         generic.NDFrame.__init__(self, data, fastpath=True)

/home/guillaume/anaconda/envs/pelican/lib/python2.7/site-packages/pandas/core/internals.pyc in __init__(self, block, axis, do_integrity_check, fastpath)
   3028             block = make_block(block,
   3029                                placement=slice(0, len(axis)),
-> 3030                                ndim=1, fastpath=True)
   3031 
   3032         self.blocks = [block]

/home/guillaume/anaconda/envs/pelican/lib/python2.7/site-packages/pandas/core/internals.pyc in make_block(values, placement, klass, ndim, dtype, fastpath)
   1835 
   1836     return klass(values, ndim=ndim, fastpath=fastpath,
-> 1837                  placement=placement)
   1838 
   1839 

/home/guillaume/anaconda/envs/pelican/lib/python2.7/site-packages/pandas/core/internals.pyc in __init__(self, values, ndim, fastpath, placement)
   1231         super(ObjectBlock, self).__init__(values, ndim=ndim,
   1232                                           fastpath=fastpath,
-> 1233                                           placement=placement)
   1234 
   1235     @property

/home/guillaume/anaconda/envs/pelican/lib/python2.7/site-packages/pandas/core/internals.pyc in __init__(self, values, placement, ndim, fastpath)
     72             raise ValueError('Wrong number of items passed %d,'
     73                              ' placement implies %d' % (
---> 74                                  len(self.values), len(self.mgr_locs)))
     75 
     76     @property

ValueError: Wrong number of items passed 12, placement implies 4

Shall I make a PR adding this test to test_multiindex or is it not worth the (minimal) work?

@jreback
Copy link
Contributor

jreback commented Jan 27, 2015

yeah this was fixed with the index refactor
sure - send a PR to confirm the behavior (if u want to look up the index refactor pr and reference that issues would be gr8)

@glyg
Copy link
Contributor Author

glyg commented Jan 27, 2015

Test added in #9362 .
I guess you're referring to #7891 which looks kinda big?

@jreback
Copy link
Contributor

jreback commented Jan 27, 2015

yep just put it in the comment in the test as well

@jreback jreback added the Testing pandas testing functions or related to the test suite label Jan 27, 2015
@jreback jreback added this to the 0.16.0 milestone Jan 27, 2015
jreback pushed a commit that referenced this issue Jan 27, 2015
jreback added a commit that referenced this issue Jan 27, 2015
TST add a test for repeat() method with MultiIndex, referenced in #9361
@jreback
Copy link
Contributor

jreback commented Jan 27, 2015

closed by #9362

@jreback jreback closed this as completed Jan 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

2 participants