0

我有一个 hdf5 数据库,这给我带来了一些麻烦。

它应该包含 3,000 个表,其中包含 6 列(整数和浮点数)加上一个索引(日期)和可变数量的行(从 100 到 10,000,000)。

从昨天开始,当我使用 ViTables '查看'数据库时,我错过了数千个表。我曾经能够在 ViTables 中看到它们。但是数据仍然存在:我仍然可以通过 Pandas 访问它们。

数据组织如下:type/source/id

例如,我可以使用以下方法同时检索 id1 和 id2:

 with pd.get_store(HDF_DATABASE) as store:
     print store['type1/source1/id1']
     print store['type2/source2/id2']

但从 ViTables,我看不到type2/source2/id2.

此外,> print store将列出type1/source1/id1但不列出type2/source2/id2

关于如何修复这些“不可见”数据表的任何建议?

编辑:

  • 错别字
  • Windows 7 32bit / Python 2.7.5 / Pandas 0.12.0(以及过去的其他版本)
  • ptdump 文件:http ://pastebin.com/7mB6bT2T
  • 正如所料,我混淆了类型源 ID
  • 看起来数据不再被引用,但只要数据库不是 ptrepack-ed 就仍然存在。

编辑2:

  • 我完全丢失了原始数据库:我无法再访问它了。该格式不再被识别。
  • 用于插入新数据的此语句(和其他类似语句)返回NaturalNameWarning警告:store.append('equity/bloomberg/4615238QCN_Equity', df)。它不尊重生成警告的自然命名要求。这可能与遇到的问题有关。
4

1 回答 1

0

示例会话

In [1]: store = pd.HDFStore('test.h5')

In [2]: store['node()'] = Series(np.arange(10))
/usr/local/lib/python2.7/site-packages/tables/path.py:99: NaturalNameWarning: object name is not a valid Python identifier: 'node()'; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you will not be able to use natural naming to access this object; using ``getattr()`` will still work, though
  NaturalNameWarning)

In [3]: store
Out[3]: 
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df                frame_table  (typ->appendable,nrows->11,ncols->2,indexers->[index],dc->[A,B])
/node()            series       (shape->[10])                                                   

In [4]: store.keys()
Out[4]: ['/df', '/node()']

In [5]: store['node()/foo'] = Series(np.arange(10))

In [6]: store.keys()
Out[6]: ['/df', '/node()', '/node()/foo']

In [7]: store
Out[7]: 
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df                    frame_table  (typ->appendable,nrows->11,ncols->2,indexers->[index],dc->[A,B])
/node()                series       (shape->[10])                                                   
/node()/foo            series       (shape->[10])                                                   

In [8]: store['my_type\mysource\id_01_01'] = Series(np.arange(10))
/usr/local/lib/python2.7/site-packages/tables/path.py:99: NaturalNameWarning: object name is not a valid Python identifier: 'my_type\\mysource\\id_01_01'; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you will not be able to use natural naming to access this object; using ``getattr()`` will still work, though
  NaturalNameWarning)

In [9]: store
Out[9]: 
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df                                   frame_table  (typ->appendable,nrows->11,ncols->2,indexers->[index],dc->[A,B])
/my_type\mysource\id_01_01            series       (shape->[10])                                                   
/node()                               series       (shape->[10])                                                   
/node()/foo                           series       (shape->[10])                                                   

In [10]: store.keys()
Out[10]: ['/df', '/my_type\\mysource\\id_01_01', '/node()', '/node()/foo']

In [11]: store['my_type/mysource/id_01_01'] = Series(np.arange(10))

In [12]: store
Out[12]: 
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df                                   frame_table  (typ->appendable,nrows->11,ncols->2,indexers->[index],dc->[A,B])
/my_type\mysource\id_01_01            series       (shape->[10])                                                   
/node()                               series       (shape->[10])                                                   
/node()/foo                           series       (shape->[10])                                                   
/my_type/mysource/id_01_01            series       (shape->[10])                                                   

问题是标识符“my_type\mysource\id_01_01”没有按照你的想法做,它“看起来”像一个文件路径。您需要反斜杠,而不是正斜杠(因为它们取决于架构)。虽然理论上这会起作用(但为了避免警告,您可能需要更改这些名称)。

于 2013-10-08T15:17:25.417 回答