File: attrs-with-padding.py

package info (click to toggle)
pytables 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,272 kB
  • sloc: ansic: 82,216; python: 65,569; cpp: 753; sh: 394; makefile: 106
file content (53 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download | duplicates (4)
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
# This is an example on how to use complex columns
import numpy as np

import tables as tb

dt = np.dtype("i4,f8", align=True)

# Create a file with regular padding
print("attrs *with* padding:")
fileh = tb.open_file(
    "attrs-with-padding.h5", mode="w", pytables_sys_attrs=False
)
attrs = fileh.root._v_attrs
# Set some attrs
attrs.pq = np.zeros(2, dt)
attrs.qr = np.ones((2, 2), dt)
attrs.rs = np.array([(1, 2)], dt)
print("repr(attrs)-->", repr(attrs))

fileh.close()

# Create a file with no padding
print("\nattrs *without* padding:")
fileh = tb.open_file(
    "attrs-without-padding.h5",
    mode="w",
    pytables_sys_attrs=False,
    allow_padding=False,
)
attrs = fileh.root._v_attrs
# Set some attrs
attrs.pq = np.zeros(2, dt)
attrs.qr = np.ones((2, 2), dt)
attrs.rs = np.array([(1, 2)], dt)
print("repr(attrs)-->", repr(attrs))

fileh.close()

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

print("attrs *with* padding:")
fileh = tb.open_file("attrs-with-padding.h5", mode="r")
attrs = fileh.root._v_attrs
print("repr(attrs)-->", repr(attrs))

fileh.close()

print("\nattrs *without* padding:")
fileh = tb.open_file("attrs-without-padding.h5", mode="r")
attrs = fileh.root._v_attrs
print("repr(attrs)-->", repr(attrs))

fileh.close()