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

Assigning to a sliced a Panel #1533

Closed
CRP opened this issue Jun 26, 2012 · 4 comments
Closed

Assigning to a sliced a Panel #1533

CRP opened this issue Jun 26, 2012 · 4 comments
Labels
Milestone

Comments

@CRP
Copy link
Contributor

CRP commented Jun 26, 2012

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?

@CRP
Copy link
Contributor Author

CRP commented Jun 26, 2012

I am using
pandas.version.version
Out[78]: '0.8.0.dev-4f1cd86'

@wesm
Copy link
Member

wesm commented Jun 29, 2012

I'll take a look and let you know. I don't believe I have any tests here so I need to at minimum specify the desired behavior at the test level

@CRP
Copy link
Contributor Author

CRP commented Jun 29, 2012

thanks, maybe the example I gave above could work as a crude test?

@wesm
Copy link
Member

wesm commented Jun 29, 2012

Fixed this. Thanks for the report

@wesm wesm closed this as completed Jun 29, 2012
yarikoptic added a commit to neurodebian/pandas that referenced this issue Jun 30, 2012
Version 0.8.0

* tag 'v0.8.0': (21 commits)
  RLS: version 0.8.0
  DOC: release notes
  BUG: _get_marker_compat insufficient on matplotlib < 1.1.0
  BUG: don't use local() in read_* functions, breaks sys.settrace. close pandas-dev#1547
  BUG: fix Panel slice setting issue and matplotlib import issues pandas-dev#1548, pandas-dev#1533
  ENH: parsers don't use tempfile
  ENH: implement DataFrameGroupBy.boxplot(), close pandas-dev#1507
  BUG: fix MultiIndex indexing issues in pandas-dev#1537, python 2.5 api fix
  BUG: fix incorrect bin labels from cut when labels=False and NA present. close pandas-dev#1511
  ENH: support file-like objects in ExcelFile, close pandas-dev#1529
  TST: skip test raising unsortable warning on 32-bit windows, other platforms. pandas-dev#1546
  BUG: raise exceptions out of trying to parse iso8601 strings
  TST: separated test case
  BUG: custom colors for bar chart pandas-dev#1540
  ENH: add 'time' as inferred_type
  ENH: datetime.time converters for plotting
  BUG: fix MultiIndex segfault due to internal refactoring. close pandas-dev#1532
  BUG: fix MultiIndex compatibility bugs described in pandas-dev#1534 post gutting internal array close pandas-dev#1534
  BUG: parser bug when parse_dates is string pandas-dev#1544
  BUG: return nameless Series and index from from_csv
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants