File: tables-with-padding.py

package info (click to toggle)
pytables 3.10.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,228 kB
  • sloc: ansic: 82,212; python: 65,296; cpp: 753; sh: 394; makefile: 100
file content (67 lines) | stat: -rw-r--r-- 2,127 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# This is an example on how to use complex columns
import numpy as np

import tables as tb

N = 1000

padded_dtype = np.dtype(
    [("string", "S3"), ("int", "i4"), ("double", "f8")], align=True
)
# assert padded_dtype.itemsize == 16
padded_struct = np.zeros(N, padded_dtype)

padded_struct["string"] = np.arange(N).astype("S3")
padded_struct["int"] = np.arange(N, dtype="i4")
padded_struct["double"] = np.arange(N, dtype="f8")

# Create a file with padding (the default)
fileh = tb.open_file(
    "tables-with-padding.h5", mode="w", pytables_sys_attrs=False
)
table = fileh.create_table(
    fileh.root, "table", padded_struct, "A table with padding"
)
print("table *with* padding -->", table)
print("table.description --> ", table.description)
print("table.descrition._v_offsets-->", table.description._v_offsets)
print("table.descrition._v_itemsize-->", table.description._v_itemsize)

fileh.close()

# Create another file without padding
fileh = tb.open_file(
    "tables-without-padding.h5",
    mode="w",
    pytables_sys_attrs=False,
    allow_padding=False,
)
table = fileh.create_table(
    fileh.root, "table", padded_struct, "A table without padding"
)
print("\ntable *without* padding -->", table)
print("table.description --> ", table.description)
print("table.descrition._v_offsets-->", table.description._v_offsets)
print("table.descrition._v_itemsize-->", table.description._v_itemsize)

fileh.close()

print("\n   ***After closing***\n")

fileh = tb.open_file("tables-with-padding.h5", mode="r")
table = fileh.root.table
print("table *with* padding -->", table)
print("table.description --> ", table.description)
print("table.descrition._v_offsets-->", table.description._v_offsets)
print("table.descrition._v_itemsize-->", table.description._v_itemsize)

fileh.close()

fileh = tb.open_file("tables-without-padding.h5", mode="r")
table = fileh.root.table
print("\ntable *without* padding -->", table)
print("table.description --> ", table.description)
print("table.descrition._v_offsets-->", table.description._v_offsets)
print("table.descrition._v_itemsize-->", table.description._v_itemsize)

fileh.close()