为什么如果我将多个空 Pandas 系列放入 hdf5 hdf5 的大小如此巨大?

Why if I put multiple empty Pandas series into hdf5 the size of hdf5 is so huge?

如果我用 pandas 创建 hdf5 文件,代码如下:

import pandas as pd

store = pd.HDFStore("store.h5")

for x in range(1000):
    store["name"+str(x)] = pd.Series()

所有系列都是空的,那么为什么 "store.h5" 文件在硬盘上占用 1.1GB space?

简短版本:您发现了一个错误。引用 this bug on GitHub

...required a bit of a hackjob (pytables doesn't like zero-length objects)

我可以在我的机器上重现这个错误。只需将您的代码更改为:

import pandas as pd
store = pd.HDFStore("store.h5")
for x in range(1000):
    store["name"+str(x)] = pd.Series([1,2])

生成一个合理的兆字节级文件。我在 Github 上找不到未解决的错误;你可以尝试报告它。

我假设你已经在你的代码中处理了这个问题,但如果你还没有,你应该检查以确保在存储对象之前没有数组维度为零:

toStore=pd.Series()
assert not np.prod( toStore.shape )==0, 'Tried to store an empty object!'