wesm/pandas — Issue #366: Traceback when calling df.as_matrix()
Author: ukch
Created: 2011-11-15 11:09:50+00:00
State: open

I have a DataFrame object that was created by importing some data in list form, pivoting it, then adding totals columns using `df.append(pandas.DataFrame(some_matrix, columns=df.columns, index=[some_tuple])` and `df[some_other_tuple] = some_array` respectively. The resulting DataFrame object looks like this:

>>> df
baz1 baz2 Totals
spam1 spam2 spam3 spam1 spam2 spam3
foo bar
foo1 bar1 NaN 20 NaN 50 NaN NaN NaN
bar2 NaN NaN 30 NaN NaN NaN NaN
foo2 bar2 NaN 40 NaN NaN NaN NaN NaN
foo3 bar1 NaN NaN NaN 60 NaN NaN NaN
Totals NaN NaN NaN NaN NaN NaN NaN

Calling `df.as_matrix()` fails with the below traceback:

>>> df.as_matrix()
Traceback (most recent call last):
File "", line 1, in
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/frame.py", line 671, in as_matrix
self._consolidate_inplace()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/generic.py", line 267, in _consolidate_inplace
self._data = self._data.consolidate()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/internals.py", line 516, in consolidate
new_blocks = _consolidate(self.blocks, self.items)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/internals.py", line 938, in _consolidate
new_block = _merge_blocks(list(group_blocks), items)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/internals.py", line 951, in _merge_blocks
do_integrity_check=True)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/internals.py", line 211, in make_block
do_integrity_check=do_integrity_check)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/internals.py", line 34, in __init__
self._check_integrity()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/internals.py", line 40, in _check_integrity
return (self.ref_locs[1:] > self.ref_locs[:-1]).all()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pandas/core/internals.py", line 47, in ref_locs
assert((indexer != -1).all())
AssertionError