1
如果我創建以下對準 numpy的陣列Pytables表D型排列
import numpy as np
import tables as pt
numrows = 10
dt = np.dtype([('date', [('year', '<i4'), ('month', '<i4'), ('day', '<i4')]),
('apples', '<f8'),
('oranges', '|S7'),
('pears', '<i4')], align=True)
x = np.zeros(numrows, dtype=dt)
for d in x.dtype.descr:
print d
和打印dtype.descr
我得到如下:
('date', [('year', '<i4'), ('month', '<i4'), ('day', '<i4')])
('', '|V4')
('apples', '<f8')
('oranges', '|S7')
('', '|V1')
('pears', '<i4')
的D型包括這些多餘的空隙「| V4 ','| V1'
現在,當我使用相同的dtype(Numpy flavor)創建一個Pytable->表時,看起來我失去了對齊。
h5file = pt.open_file('mytable.h5', mode='w')
table = h5file.create_table('/', 'mytable', dt, filters=None, expectedrows=numrows, byteorder='little')
policy = table.row
for j in xrange(numrows):
for field in table.colnames:
if (field == 'date'):
policy[field] = (2014, 1, 8)
else:
policy[field] = 0
policy.append()
table.flush()
mytable = h5file.root.mytable[:]
h5file.close()
for d in mytable.dtype.descr:
print d
它的輸出是:
('date', [('year', '<i4'), ('month', '<i4'), ('day', '<i4')])
('apples', '<f8')
('oranges', '|S7')
('pears', '<i4')
沒有更多的 '| V' 空間
我怎樣才能構建一個Pytable->表使得對準被保留(保持' | V'空格)?