Skip to content

Assigning to a sliced a Panel #1533

@CRP

Description

@CRP

Suppose I have:

a=Panel(items=[1,2,3],major_axis=[11,22,33],minor_axis=[111,222,333])
b=DataFrame(randn(2,3),index=[111,333],columns=[1,2,3])

I get an error when trying to assign b to a slice of a:

a.ix[:,22,[111,333]]=b

ValueError Traceback (most recent call last)
in ()
----> 1 a.ix[:,22,[111,333]]=b
/usr/local/lib/python2.7/site-packages/pandas/core/indexing.pyc in setitem(self, key, value)
66 indexer = self._convert_to_indexer(key)
67
---> 68 self._setitem_with_indexer(indexer, value)
69
70 def _convert_tuple(self, key):
/usr/local/lib/python2.7/site-packages/pandas/core/indexing.pyc in _setitem_with_indexer(self, indexer, value)
101 if isinstance(indexer, tuple):
102 indexer = _maybe_convert_ix(*indexer)
--> 103 self.obj.values[indexer] = value
104
105 def _getitem_tuple(self, tup):
ValueError: array is not broadcastable to correct shape

The slice of a and b look of same shape to me, so I do not understand the broadcasting error.

When debugging _setitem_with_indexer() I notice that the indexer returns a 2x3 array instead of 3x2, so if I do:

a.ix[:,22,[111,333]]=b.T

then it works. Is this a bug or the intended behaviour?

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