【问题标题】:HDFStore error 'correct atom type -> [dtype->uint64'HDFStore 错误'正确的原子类型-> [dtype->uint64'
【发布时间】:2013-05-01 18:30:55
【问题描述】:

第一次使用 read_hdf 喜欢它想用它将一堆较小的 *.h5 组合成一个大文件。计划调用 HDFStore 的 append()。稍后将添加分块以节省内存。

示例表如下所示

Int64Index:220189 个条目,0 到 220188 数据列(共16列): ID 220189 非空值 持续时间 220189 个非空值 epochNanos 220189 个非空值 标记 220189 个非空值 数据类型:对象(1),uint64(3)

代码:

import pandas as pd
print pd.__version__  # I am running 0.11.0
dest_h5f = pd.HDFStore('c:\\t3_combo.h5',complevel=9)
df = pd.read_hdf('\\t3\\t3_20130319.h5', 't3', mode = 'r')
print df
dest_h5f.append(tbl, df, data_columns=True)
dest_h5f.close()

问题:追加捕获此异常 例外:找不到正确的原子类型 -> [dtype->uint64,items->Index([InstrumentID], dtype=object)] 'module' 对象没有属性 'Uint64Col'

这感觉像是某些版本的 pytables 或 numpy 的问题 pytables = v 2.4.0 numpy = v 1.6.2

【问题讨论】:

  • 这只是在 master:github.com/pydata/pandas/pull/3494 中修复的,你可以试试看吗? (也将在 0.11.1 版本中),应该很快
  • 另请注意,uint64 不能用于索引(尽管作为列不应该是问题)
  • 可以在补丁版本上运行。我将如何强制它使用支持的 dtype 索引。我所有的字段都是 uint64 和字符串。我尝试了 df = df.reset_index(drop = True) 但我似乎仍然有 NotImplementedError: indexing 64-bit unsigned integer columns is not supported, sorry
  • 你真的需要 uint64 有什么原因吗?而不是int64? uint64 不适合索引(与 HDFStore 无关)
  • 我已经回到源文件的起源了...(我没有写那个。)看看它是否是一个简单的东西交换出来。看起来像这样 final_df.to_records().astype([('epochNanos_cmi', 'i8'),... ...

标签: pandas pytables


【解决方案1】:

我们通常将 epcoch 秒表示为 int64 并使用 datetime64[ns]。尝试使用datetime64[ns],会让您的生活更轻松。无论如何,自 1970 年以来的纳秒都在 in64 的范围内。 (而 uint64 只给你买这个范围的 2 倍)。所以使用无符号整数并没有真正的优势。

我们使用 int64 是因为最小值 (-9223372036854775807) 用于表示 NaT 或表示 Not a Time 的整数标记

In [11]: (Series([Timestamp('20130501')])-
                Series([Timestamp('19700101')]))[0].astype('int64')
Out[11]: 1367366400000000000

In [12]: np.iinfo('int64').max
Out[12]: 9223372036854775807

然后您可以在纳秒级别表示大约 1677 年到 2264 年的时间形式

【讨论】:

    猜你喜欢
    • 2013-03-18
    • 2013-03-07
    • 2018-11-30
    • 2015-01-16
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 2017-02-05
    • 2018-08-12
    相关资源
    最近更新 更多