pd.read_hdf 抛出 'cannot set WRITABLE flag to True of this array'

pd.read_hdf throws 'cannot set WRITABLE flag to True of this array'

当运行

pd.read_hdf('myfile.h5')

我收到以下回溯错误:

[[...some longer traceback]]

~/.local/lib/python3.6/site-packages/pandas/io/pytables.py in read_array(self, key, start, stop) 2487 2488 if isinstance(node, tables.VLArray): -> 2489 ret = node[0][start:stop] 2490 else: 2491 dtype = getattr(attrs, 'value_type', None)

~/.local/lib/python3.6/site-packages/tables/vlarray.py in getitem(self, key)

~/.local/lib/python3.6/site-packages/tables/vlarray.py in read(self, start, stop, step)

tables/hdf5extension.pyx in tables.hdf5extension.VLArray._read_array()

ValueError: cannot set WRITEABLE flag to True of this array

不知道发生了什么。我已经尝试重新安装 tablespandas 基本上所有的东西,但不想阅读它。

您使用的是 numpy 1.16 吗?它与最新版本的 pytables 不兼容(参见 https://github.com/PyTables/PyTables/blob/v3.4.4/tables/hdf5extension.pyx#L2155) but the pytables team have not yet released a fixed version: https://github.com/PyTables/PyTables/issues/719

我发现解决这个问题的唯一方法是降级 numpy。

似乎是 time-date 字符串导致了问题,当我将这些字符串从文本转换为 numpy (pd.to_datetime()) 并存储 table 时,问题就消失了,所以也许它有问题与文本数据有关吗?

将 PyTables 升级到版本 > 3.5.1 应该可以解决这个问题。

pip install --upgrade tables