Skip to content

Regression issue with concat of panels in 0.9.1 #2257

@jreback

Description

@jreback

concat of panels with the same items and minor_axis (but different major_axis) on axis=2 worked in 0.8.1, but fails in 0.9.1

In [1]: import numpy as np

In [2]: import pandas

In [3]: pandas.__version__
Out[3]: '0.9.1'

In [4]: def make_panel():
   ...:         index = 5
   ...:         cols  = 3
   ...:         return pandas.Panel(dict([ ("Item%s" % x,pandas.DataFrame(np.random.randn(index,cols),index = [ "I%s" % i for i in range(index) ], columns = [ "C%s" % i for i in range(cols) ])) for x in ['A','B','C'] ]))
   ...: 

In [5]: panel1 = make_panel()

In [6]: panel1
Out[6]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 5 (major) x 3 (minor)
Items: ItemA to ItemC
Major axis: I0 to I4
Minor axis: C0 to C2

In [7]: panel2 = make_panel()

In [8]: panel2 = panel2.rename_axis(dict([ (x,"%s_1" % x) for x in panel2.major_axis ]), axis=1)

In [9]: panel2
Out[9]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 5 (major) x 3 (minor)
Items: ItemA to ItemC
Major axis: I0_1 to I4_1
Minor axis: C0 to C2

In [10]: panel3 = make_panel()

In [11]: panel3 = panel2.rename_axis(dict([ (x,"%s_1" % x) for x in panel2.major_axis ]), axis=1).rename_axis(dict([ (x,"%s_1" % x) for x in panel2.minor_axis ]), axis=2)

In [12]: panel3
Out[12]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 5 (major) x 3 (minor)
Items: ItemA to ItemC
Major axis: I0_1_1 to I4_1_1
Minor axis: C0_1 to C2_1

this works in 0.8.1 & 0.9.1

In [14]: pandas.concat([ panel1, panel2 ], axis = 1, verify_integrity = True)
Out[14]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 10 (major) x 3 (minor)
Items: ItemA to ItemC
Major axis: I0 to I4_1
Minor axis: C0 to C2

fails under 0.9.1 (worked in 0.8.1)

In [16]: pandas.concat([ panel1, panel3 ], axis = 1, verify_integrity = True)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-16-72a0267c3f61> in <module>()
----> 1 pandas.concat([ panel1, panel3 ], axis = 1, verify_integrity = True)

/usr/local/lib/python2.7/site-packages/pandas-0.9.1-py2.7-linux-x86_64.egg/pandas/tools/merge.pyc in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity)
    877                        keys=keys, levels=levels, names=names,
    878                        verify_integrity=verify_integrity)
--> 879     return op.get_result()
    880 
    881 

/usr/local/lib/python2.7/site-packages/pandas-0.9.1-py2.7-linux-x86_64.egg/pandas/tools/merge.pyc in get_result(self)
    959         else:
    960             new_data = self._get_concatenated_data()
--> 961             return self.objs[0]._from_axes(new_data, self.new_axes)
    962 
    963     def _get_fresh_axis(self):

/usr/local/lib/python2.7/site-packages/pandas-0.9.1-py2.7-linux-x86_64.egg/pandas/core/panel.pyc in _from_axes(cls, data, axes)
    241             items, major, minor = axes
    242             return cls(data, items=items, major_axis=major,
--> 243                        minor_axis=minor, copy=False)
    244 
    245     def _init_dict(self, data, axes, dtype=None):

/usr/local/lib/python2.7/site-packages/pandas-0.9.1-py2.7-linux-x86_64.egg/pandas/core/panel.pyc in __init__(self, data, items, major_axis, minor_axis, copy, dtype)
    221             mgr = data
    222         elif isinstance(data, dict):
--> 223             mgr = self._init_dict(data, passed_axes, dtype=dtype)
    224             copy = False
    225             dtype = None

/usr/local/lib/python2.7/site-packages/pandas-0.9.1-py2.7-linux-x86_64.egg/pandas/core/panel.pyc in _init_dict(self, data, axes, dtype)
    280             arrays.append(values)
    281 
--> 282         return self._init_arrays(arrays, items,  axes)
    283 
    284     def _init_arrays(self, arrays, arr_names, axes):

/usr/local/lib/python2.7/site-packages/pandas-0.9.1-py2.7-linux-x86_64.egg/pandas/core/panel.pyc in _init_arrays(self, arrays, arr_names, axes)
    285         # segregates dtypes and forms blocks matching to columns
    286         blocks = form_blocks(arrays, arr_names, axes)
--> 287         mgr = BlockManager(blocks, axes).consolidate()
    288         return mgr
    289 

/usr/local/lib/python2.7/site-packages/pandas-0.9.1-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in __init__(self, blocks, axes, do_integrity_check)
    484 
    485         if do_integrity_check:
--> 486             self._verify_integrity()
    487 
    488     @classmethod

/usr/local/lib/python2.7/site-packages/pandas-0.9.1-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in _verify_integrity(self)
    566         for block in self.blocks:
    567             assert(block.ref_items is self.items)
--> 568             assert(block.values.shape[1:] == mgr_shape[1:])
    569         tot_items = sum(len(x.items) for x in self.blocks)
    570         assert(len(self.items) == tot_items)

AssertionError: 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions