[英]PyTables: Change Table expectedrows parameter dynamically
在 PyTables 優化提示中,我們可以在創建新表時找到對 append expectedrows參數的建議 - File.create_table() 。
但是,我找不到有關以后更改此參數的可能性的任何信息。 這是合理的,因為我的表不是 static 並且會隨着時間的推移而增長,我想持續使用它。
或者,是否可以創建一個新表(具有新設置)並使用來自其他已存在表的數據?
或者,處理此問題的最佳解決方案是什么?
我不知道在創建表后訪問expectedrows
的值或更改的方法。 但是,讀取表並將數據復制到新表(在同一文件或另一個文件中)“相對容易”。 注意:如果您創建一個新表並刪除舊表,您將需要按照上面提到的PyTables 優化提示中的描述運行ptrepack
。)
下面的簡單示例:
import tables as tb
import numpy as np
with tb.File('SO_71267946.h5', 'w') as h5f:
arr_dt = [('i', int), ('x',float), ('y',float)]
arr = np.empty(dtype=arr_dt, shape=10,)
arr['i'] = [i for i in range(10)]
arr['x'] = [2.*x for x in range(10)]
arr['y'] = [4.*y for y in range(10)]
ex_tbl = h5f.create_table('/','Example',obj=arr, expectedrows=1_000)
print(ex_tbl.chunkshape)
# create more data to add more rows to the table
arr = np.empty(dtype=arr_dt, shape=20,)
arr['i'] = [i for i in range(10,30)]
arr['x'] = [2.*x for x in range(10,30)]
arr['y'] = [4.*y for y in range(10,30)]
ex_tbl.append(arr)
# Copy to a new table in the same file:
xfer = h5f.root.Example.read()
ex_tbl2 = h5f.create_table('/','Example2',obj=xfer, expectedrows=1_000_000)
print(ex_tbl2.chunkshape)
# Copy to a new table in the new file:
with tb.File('SO_71267946.h5', 'r') as h5r, \
tb.File('SO_71267946_2.h5', 'w') as h5w:
xfer = h5r.root.Example.read()
ex_tbl2 = h5w.create_table('/','Example2',obj=xfer, expectedrows=1_000_000)
下表顯示了針對expectedrows
的不同值計算的chuckshape
。 ( chuckshape
是在單個 I/O 操作中從表中讀取的行數。)
預期的行 | 大塊形狀 |
---|---|
10_000 | (3276,) |
100_000 | (3276,) |
1_000_000 | (6553,) |
10_000_000 | (13107,) |
1_000_000_000 | (52428,) |
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.