【发布时间】:2021-08-09 06:04:56
【问题描述】:
我在 pytables 中创建了一个表,如下所示:
import tables as tb
import random
import time
h5f = tb.open_file('enum.h5', 'w')
class BallExt(tb.IsDescription):
ballTime = tb.Time32Col()
ballColor = tb.Int64Col()
tbl = h5f.create_table('/', 'df', BallExt)
now = time.time()
row = tbl.row
for i in range(10000):
row['ballTime'] = now + i
row['ballColor'] = int(random.choice([1,2,3,4,5])) # take note of this
row.append()
tbl.flush()
h5f.close()
这个数据库在磁盘中的文件大小显示为133KB。
现在,当我尝试删除表时,一切正常(最终文件大小约为 1KB)。
h5f = tb.open_file('enum.h5', 'a')
tbl = h5f.root.df
tbl.remove()
h5f.flush()
h5f.close()
但是,如果我将此表的一部分复制到新表并删除原始表,文件大小似乎会增加(达到 263KB)。看起来唯一的一些引用被删除了,数据仍然存在于磁盘中。
h5f = tb.open_file('enum.h5', 'a')
tbl = h5f.root.df
new_tbl = h5f.create_table('/', 'df2', BallExt)
tbl.append_where(new_tbl, '(ballColor >= 3)')
tbl.remove()
h5f.flush()
h5f.close()
这是预期的吗?如果是这样,有没有办法删除tbl 以及释放表占用的磁盘空间? (我用的是pytables==3.6.1)
【问题讨论】: