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

Saving DataFrame with tuple index to HDFStore fails #492

Closed
andreas-h opened this issue Dec 15, 2011 · 1 comment

Comments

Projects
None yet
2 participants
@andreas-h
Copy link
Contributor

commented Dec 15, 2011

The following code fails on pandas 0.6.1

import numpy as np
import pandas
col = np.arange(10)
idx = [(0.,1.), (2., 3.), (4., 5.)]
data = np.random.randn(30).reshape((3, 10))
DF = pandas.DataFrame(data, index=idx, columns=col)
H = pandas.HDFStore("test.h5", "w")
H['data'] = DF
H.close()

The traceback is as follows:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/home2/hilboll/<ipython-input-15-a313de079f58> in <module>()
----> 1 H['data'] = DF

/home2/hilboll/.virtualenvs/pydoas/lib/python2.7/site-packages/pandas/io/pytables.pyc in __setitem__(self, key, value)
    121 
    122     def __setitem__(self, key, value):
--> 123         self.put(key, value)
    124 
    125     def __len__(self):

/home2/hilboll/.virtualenvs/pydoas/lib/python2.7/site-packages/pandas/io/pytables.pyc in put(self, key, value, table, append, compression)
    259         """
    260         self._write_to_group(key, value, table=table, append=append,
--> 261                              comp=compression)
    262 
    263     def _get_handler(self, op, kind):

/home2/hilboll/.virtualenvs/pydoas/lib/python2.7/site-packages/pandas/io/pytables.pyc in _write_to_group(self, key, value, table, append, comp)
    327             wrapper = lambda value: handler(group, value)
    328 
--> 329         wrapper(value)
    330         group._v_attrs.pandas_type = kind
    331 

/home2/hilboll/.virtualenvs/pydoas/lib/python2.7/site-packages/pandas/io/pytables.pyc in <lambda>(value)
    325 
    326             handler = self._get_handler(op='write', kind=kind)
--> 327             wrapper = lambda value: handler(group, value)
    328 
    329         wrapper(value)

/home2/hilboll/.virtualenvs/pydoas/lib/python2.7/site-packages/pandas/io/pytables.pyc in _write_frame(self, group, df)
    336 
    337     def _write_frame(self, group, df):
--> 338         self._write_block_manager(group, df._data)
    339 
    340     def _read_frame(self, group, where=None):

/home2/hilboll/.virtualenvs/pydoas/lib/python2.7/site-packages/pandas/io/pytables.pyc in _write_block_manager(self, group, data)
    347         group._v_attrs.ndim = data.ndim
    348         for i, ax in enumerate(data.axes):
--> 349             self._write_index(group, 'axis%d' % i, ax)
    350 
    351         # Supporting mixed-type DataFrame objects...nontrivial


/home2/hilboll/.virtualenvs/pydoas/lib/python2.7/site-packages/pandas/io/pytables.pyc in _write_index(self, group, key, index)
    439         else:
    440             setattr(group._v_attrs, '%s_variety' % key, 'regular')
--> 441             converted, kind, _ = _convert_index(index)
    442             self._write_array(group, key, converted)
    443             node = getattr(group, key)

/home2/hilboll/.virtualenvs/pydoas/lib/python2.7/site-packages/pandas/io/pytables.pyc in _convert_index(index)
    734         return np.asarray(values, dtype=np.float64), 'float', atom
    735     else: # pragma: no cover
--> 736         raise ValueError('unrecognized index type %s' % type(values[0]))
    737 
    738 def _read_array(group, key):

ValueError: unrecognized index type <type 'tuple'>
@wesm

This comment has been minimized.

Copy link
Member

commented Dec 15, 2011

fixed in the above commit

@wesm wesm closed this Dec 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.