1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
9
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
11
TITLE="PyTables User's Guide"
12
HREF="index.html"><LINK
14
TITLE="Library Reference"
15
HREF="c1381.html"><LINK
17
TITLE="The AttributeSet
19
HREF="x4306.html"><LINK
21
TITLE="Helper classes"
22
HREF="x4983.html"></HEAD
33
SUMMARY="Header navigation table"
45
> User's Guide: Hierarchical datasets in Python - Release 1.3.2</TH
61
>Chapter 4. Library Reference</TD
82
>4.16. Declarative classes</A
85
NAME="declarativeClasses"
88
>In this section a series of classes that are meant to
95
> datatypes that are required for primary
97
CLASS="computeroutput"
100
CLASS="computeroutput"
104
CLASS="computeroutput"
106
> ) objects are described.
113
NAME="subsection4.16.1"
121
NAME="IsDescriptionClassDescr"
124
>This class is designed to be used as an easy, yet
125
meaningful way to describe the properties of
127
CLASS="computeroutput"
129
> objects through the definition of
136
> that inherit properties from it.
137
In order to define such a class, you must declare it as
145
attributes as columns you want in your table. The name of
146
each attribute will become the name of a column, and its
147
value will hold a description of it.
150
>Ordinary columns can be described using instances of the
152
CLASS="computeroutput"
155
HREF="x4389.html#ColClassDescr"
158
columns can be described by using classes derived from
160
CLASS="computeroutput"
162
> or instances of it. Derived
163
classes can be declared in place (in which case the column
164
takes the name of the class) or referenced by name, and
165
they can have a <SAMP
166
CLASS="computeroutput"
169
which sets the position of the nested column among its
173
>Once you have created a description object, you can pass
175
CLASS="computeroutput"
177
> constructor, where all the
178
information it contains will be used to define the table
179
structure. See the <A
180
HREF="x1017.html#secondExample"
182
> for an example on how
186
>See below for a complete list of the special attributes
187
that can be specified to complement the
195
CLASS="computeroutput"
205
NAME="subsubsection4.16.1.1"
213
NAME="IsDescription.specialAttrs"
225
table. It can take <SPAN
238
> values. This determines the type of
239
objects returned during input (i.e. read) operations.
250
CLASS="computeroutput"
253
HREF="x4983.html#IndexPropsClassDescr"
256
use this to alter the properties of the index
257
creation process for a table.
266
>Sets the position of a
267
possible nested column description among its sibling
280
NAME="subsection4.16.2"
292
CLASS="computeroutput"
294
> class is used as a mean to declare
295
the different properties of a table column. In addition, a
296
series of descendant classes are offered in order to make
297
these column descriptions easier to the user. In general,
298
it is recommended to use these descendant classes, as they
299
are more meaningful when found in the middle of the code.
306
NAME="subsubsection4.16.2.1"
322
>The type class of the column.
331
>The string type of the column.
342
CLASS="computeroutput"
344
> format, of the column.
353
>The shape of the column.</P
361
>The size of the base
362
items. Specially useful for <SAMP
363
CLASS="computeroutput"
375
>Whether this column is meant
376
to be indexed or not.</P
384
>The position of this column
385
with regard to its column siblings.</P
393
>The name of this column</P
401
>The complete pathname of
402
the column. This is mainly useful in nested columns;
403
for non-nested ones this value is the same a
405
CLASS="computeroutput"
418
NAME="subsubsection4.16.2.2"
433
NAME="subsubsection4.16.2.3"
441
>A description of the different constructors with their
449
>Col(dtype="Float64", shape=1, dflt=None, pos=None,
455
>Declare the properties of a <SAMP
456
CLASS="computeroutput"
471
>The data type for the
472
column. All types listed in <A
473
HREF="a6585.html#datatypesSupported"
476
data types for columns. The type description is
477
accepted both in string-type format and as a
478
numarray data type.</P
486
>An integer or a tuple, that
487
specifies the number of <SPAN
494
each element (or shape, for multidimensional
495
elements) of this column. For <SAMP
496
CLASS="computeroutput"
499
columns, the last dimension is used as the length
500
of the character strings. However, for this kind of
501
objects, the use of <SAMP
502
CLASS="computeroutput"
505
is strongly recommended.</P
513
>The default value for
514
elements of this column. If the user does not
515
supply a value for an element while filling a
516
table, this default value will be written to
517
disk. If the user supplies an scalar value for a
518
multidimensional column, this value is
526
elements in the column cell. If <SPAN
533
not supplied, an appropriate zero value (or
540
> string) will be chosen by default.
541
Please, note that all the default values are kept
542
internally as numarray objects. </P
550
>By default, columns are
551
arranged in memory following an alpha-numerical
552
order of the column names. In some situations,
553
however, it is convenient to impose a user defined
560
> parameter allows the user
561
to force the desired ordering.</P
569
>Whether this column should
570
be indexed for better performance in table
580
>StringCol(length=None, dflt=None, shape=1, pos=None,
586
>Declare a column to be of type
588
CLASS="computeroutput"
597
sets the length of the strings. The meaning of the other
598
parameters are like in the <SAMP
599
CLASS="computeroutput"
606
>BoolCol(dflt=0, shape=1, pos=None, indexed=0) </B
610
>Define a column to be of type <SAMP
611
CLASS="computeroutput"
614
The meaning of the parameters are the same of those in
616
CLASS="computeroutput"
623
>IntCol(dflt=0, shape=1, itemsize=4, sign=1,
629
>Declare a column to be of type <SAMP
630
CLASS="computeroutput"
633
depending on the value of <SPAN
640
that sets the number of bytes of the integers in the
647
> determines whether the integers
648
are signed or not. The meaning of the other parameters
649
are the same of those in the <SAMP
650
CLASS="computeroutput"
656
>This class has several descendants:
666
>Int8Col(dflt=0, shape=1, pos=None,
671
>Define a column of type
673
CLASS="computeroutput"
679
>UInt8Col(dflt=0, shape=1, pos=None,
684
>Define a column of type
686
CLASS="computeroutput"
692
>Int16Col(dflt=0, shape=1, pos=None, indexed=0)</B
696
>Define a column of type <SAMP
697
CLASS="computeroutput"
703
>UInt16Col(dflt=0, shape=1, pos=None, indexed=0)</B
707
>Define a column of type <SAMP
708
CLASS="computeroutput"
714
>Int32Col(dflt=0, shape=1, pos=None, indexed=0)</B
718
>Define a column of type <SAMP
719
CLASS="computeroutput"
725
>UInt32Col(dflt=0, shape=1, pos=None, indexed=0)</B
729
>Define a column of type <SAMP
730
CLASS="computeroutput"
736
>Int64Col(dflt=0, shape=1, pos=None, indexed=0)</B
740
>Define a column of type <SAMP
741
CLASS="computeroutput"
747
>UInt64Col(dflt=0, shape=1, pos=None, indexed=0)</B
751
>Define a column of type <SAMP
752
CLASS="computeroutput"
764
>FloatCol(dflt=0.0, shape=1, itemsize=8, pos=None,
770
>Define a column to be of type <SAMP
771
CLASS="computeroutput"
774
depending on the value of <SAMP
775
CLASS="computeroutput"
779
CLASS="computeroutput"
781
> parameter sets the number of bytes
782
of the floats in the column and the default is 8 bytes
783
(double precision). The meaning of the other parameters
784
are the same as those in the <SAMP
785
CLASS="computeroutput"
791
>This class has two descendants:
801
>Float32Col(dflt=0.0, shape=1, pos=None,
806
>Define a column of type
808
CLASS="computeroutput"
814
>Float64Col(dflt=0.0, shape=1, pos=None,
819
>Define a column of type
821
CLASS="computeroutput"
832
>ComplexCol(dflt=0.+0.j, shape=1, itemsize=16, pos=None)
837
>Define a column to be of type
839
CLASS="computeroutput"
841
>, depending on the value of
843
CLASS="computeroutput"
846
CLASS="computeroutput"
849
parameter sets the number of bytes of the complex types
850
in the column and the default is 16 bytes (double
851
precision complex). The meaning of the other parameters
852
are the same as those in the <SAMP
853
CLASS="computeroutput"
859
>This class has two descendants:
869
>Complex32Col(dflt=0.+0.j, shape=1, pos=None)</B
873
>Define a column of type <SAMP
874
CLASS="computeroutput"
880
>Float64Col(dflt=0+0.j, shape=1, pos=None)</B
884
>Define a column of type <SAMP
885
CLASS="computeroutput"
896
CLASS="computeroutput"
898
> columns and its descendants
899
do not support indexation.</P
905
>TimeCol(dflt=0, shape=1, itemsize=8, pos=None,
911
>Define a column to be of type <SPAN
918
kinds of time columns are supported depending on the
920
CLASS="computeroutput"
922
>: 4-byte signed integer
923
and 8-byte double precision floating point columns
924
(the default ones). The meaning of the other
925
parameters are the same as those in the
927
CLASS="computeroutput"
933
>Time columns have a special encoding in the HFD5 file.
935
HREF="a6585.html#datatypesSupported"
938
for more information on those types.
944
>This class has two descendants:
954
>Time32Col(dflt=0, shape=1, pos=None,
959
>Define a column of type
961
CLASS="computeroutput"
967
>Time64Col(dflt=0.0, shape=1, pos=None,
972
>Define a column of type
974
CLASS="computeroutput"
985
>EnumCol(enum, dflt, dtype='UInt32', shape=1, pos=None,
993
>Description of a column of an enumerated type.</P
998
>Instances of this class describe a table column which
999
stores enumerated values. Those values belong to an
1000
enumerated type, defined by the first argument
1002
CLASS="computeroutput"
1004
>) in the constructor of
1006
CLASS="computeroutput"
1008
>, which accepts the same kinds of
1010
CLASS="computeroutput"
1013
HREF="x4983.html#EnumClassDescr"
1015
>). The enumerated type
1016
is stored in the <SAMP
1017
CLASS="computeroutput"
1026
>A default value must be specified as the second
1028
CLASS="computeroutput"
1030
>) in the constructor; it
1037
> (a string) of one of the
1038
enumerated values in the enumerated type. Once the
1039
column is created, the corresponding concrete value
1040
is stored in its <SAMP
1041
CLASS="computeroutput"
1044
the name does not match any value in the enumerated
1046
CLASS="computeroutput"
1054
>A numarray data type might be specified in order
1055
to determine the base type used for storing the
1056
values of enumerated values in memory and disk.
1057
The data type must be able to represent each and
1058
every concrete value in the enumeration. If it is
1060
CLASS="computeroutput"
1063
default base type is unsigned 32-bit integer,
1064
which is sufficient for most cases.
1071
CLASS="computeroutput"
1073
> attribute of enumerated
1074
columns is always <SAMP
1075
CLASS="computeroutput"
1079
CLASS="computeroutput"
1081
> attribute is the data type used
1082
for storing concrete values.
1088
>The shape, position and indexed attributes of the
1089
column are treated as with other column description
1091
HREF="x4389.html#ColClassDescr"
1107
NAME="subsection4.16.3"
1115
NAME="AtomClassDescr"
1119
CLASS="computeroutput"
1121
> class is a descendant of the
1123
CLASS="computeroutput"
1126
HREF="x4389.html#ColClassDescr"
1128
>) and is meant to declare the
1129
different properties of the <SPAN
1143
CLASS="computeroutput"
1147
CLASS="computeroutput"
1150
CLASS="computeroutput"
1154
CLASS="computeroutput"
1156
> instances have the property that their
1157
length is always the same. However, you can grow objects
1158
along the extensible dimension in the case of
1160
CLASS="computeroutput"
1162
> or put a variable number of them on a
1164
CLASS="computeroutput"
1166
> row. Moreover, the atoms are not
1167
restricted to scalar values, and they can be fully
1168
multidimensional objects.
1171
>A series of descendant classes are offered in order to
1172
make the use of these element descriptions easier. In
1173
general, it is recommended to use these descendant
1174
classes, as they are more meaningful when found in the
1182
NAME="subsubsection4.16.3.1"
1187
instance variables</A
1190
>In addition to the variables that it inherits from the
1192
CLASS="computeroutput"
1194
> class, it has the next additional
1205
>The object representation for
1206
this atom. See below on constructors description for
1208
CLASS="computeroutput"
1210
> class the possible values it can
1222
NAME="subsubsection4.16.3.2"
1238
>Returns the total length,
1239
in bytes, of the element base atom. If its shape is
1240
has one zero element on it (for use in
1242
CLASS="computeroutput"
1244
>, for example), this is replaced
1245
by an one in order to compute the atom size correctly.
1256
NAME="subsubsection4.16.3.3"
1264
>A description of the different constructors with their
1272
>Atom(dtype="Float64", shape=1, flavor="numarray")
1277
>Define properties for the base elements of
1279
CLASS="computeroutput"
1282
CLASS="computeroutput"
1286
CLASS="computeroutput"
1299
>The data type for the base
1301
HREF="a6585.html#datatypesSupported"
1304
relation of data types supported. The type
1305
description is accepted both in string-type format
1306
and as a numarray data type.
1316
CLASS="computeroutput"
1319
context, it is a <SPAN
1326
specifying the shape of the object, and one (and only
1327
one) of its dimensions <SPAN
1333
> be 0, meaning that the
1335
CLASS="computeroutput"
1337
> object will be enlarged along
1338
this axis. In the case of a <SAMP
1339
CLASS="computeroutput"
1342
can be an integer with a value of 1 (one) or a
1343
tuple, that specifies whether the atom is an scalar
1344
(in the case of a 1) or has multiple dimensions (in
1345
the case of a tuple). For
1347
CLASS="computeroutput"
1349
> elements, the last dimension
1350
is used as the length of the character
1351
strings. However, for this kind of objects, the use
1353
CLASS="computeroutput"
1355
> subclass is strongly
1366
representation for this atom. It can be any of
1386
> for the character types and
1413
numerical types. If specified, the read atoms
1414
will be converted to that specific flavor. If
1415
not specified, the atoms will remain in their
1416
native format (i.e. <SAMP
1417
CLASS="computeroutput"
1430
>StringAtom(shape=1, length=None,
1431
flavor="numarray")</B
1435
>Define an atom to be
1437
CLASS="computeroutput"
1439
> type. The meaning of the
1446
> parameter is the same as in the
1448
CLASS="computeroutput"
1457
length of the strings atoms. <SPAN
1465
CLASS="computeroutput"
1469
CLASS="computeroutput"
1473
CLASS="computeroutput"
1475
>. Unicode strings are not
1476
supported by this type; see the
1478
CLASS="computeroutput"
1480
> class if you want Unicode
1481
support (only available for <SAMP
1482
CLASS="computeroutput"
1490
>BoolAtom(shape=1, flavor="numarray") </B
1494
>Define an atom to be of type <SAMP
1495
CLASS="computeroutput"
1498
The meaning of the parameters are the same of those in
1500
CLASS="computeroutput"
1507
>IntAtom(shape=1, itemsize=4, sign=1,
1508
flavor="numarray") </B
1512
>Define an atom to be of
1514
CLASS="computeroutput"
1516
>, depending on the value of
1523
> parameter, that sets the number of
1524
bytes of the integers that conform the
1531
> determines whether the integers are
1532
signed or not. The meaning of the other parameters are
1533
the same of those in the <SAMP
1534
CLASS="computeroutput"
1540
>This class has several descendants:
1550
>Int8Atom(shape=1, flavor="numarray")</B
1554
>Define an atom of type <SAMP
1555
CLASS="computeroutput"
1561
>UInt8Atom(shape=1, flavor="numarray")</B
1565
>Define an atom of type <SAMP
1566
CLASS="computeroutput"
1572
>Int16Atom(shape=1, flavor="numarray")</B
1576
>Define an atom of type <SAMP
1577
CLASS="computeroutput"
1583
>UInt16Atom(shape=1, flavor="numarray")</B
1587
>Define an atom of type <SAMP
1588
CLASS="computeroutput"
1594
>Int32Atom(shape=1, flavor="numarray")</B
1598
>Define an atom of type <SAMP
1599
CLASS="computeroutput"
1605
>UInt32Atom(shape=1, flavor="numarray")</B
1609
>Define an atom of type <SAMP
1610
CLASS="computeroutput"
1616
>Int64Atom(shape=1, flavor="numarray")</B
1620
>Define an atom of type <SAMP
1621
CLASS="computeroutput"
1627
>UInt64Atom(shape=1, flavor="numarray")</B
1631
>Define an atom of type <SAMP
1632
CLASS="computeroutput"
1644
>FloatAtom(shape=1, itemsize=8, flavor="numarray")
1649
>Define an atom to be of <SAMP
1650
CLASS="computeroutput"
1653
type, depending on the value of <SAMP
1654
CLASS="computeroutput"
1658
CLASS="computeroutput"
1660
> parameter sets the number of bytes
1661
of the floats in the atom and the default is 8 bytes
1662
(double precision). The meaning of the other parameters
1663
are the same as those in the <SAMP
1664
CLASS="computeroutput"
1670
>This class has two descendants:
1680
>Float32Atom(shape=1, flavor="numarray")</B
1684
>Define an atom of type <SAMP
1685
CLASS="computeroutput"
1691
>Float64Atom(shape=1, flavor="numarray")</B
1695
>Define an atom of type <SAMP
1696
CLASS="computeroutput"
1707
>ComplexAtom(shape=1, itemsize=16, flavor="numarray")
1712
>Define an atom to be of <SAMP
1713
CLASS="computeroutput"
1716
depending on the value of <SAMP
1717
CLASS="computeroutput"
1721
CLASS="computeroutput"
1723
> parameter sets the number of bytes
1724
of the floats in the atom and the default is 16 bytes
1725
(double precision complex). The meaning of the other
1726
parameters are the same as those in the
1728
CLASS="computeroutput"
1734
>This class has two descendants:
1744
>Complex32Atom(shape=1, flavor="numarray")</B
1748
>Define an atom of type <SAMP
1749
CLASS="computeroutput"
1755
>Complex64Atom(shape=1, flavor="numarray")</B
1759
>Define an atom of type <SAMP
1760
CLASS="computeroutput"
1771
>TimeAtom(shape=1, itemsize=8, flavor="numarray")
1776
>Define an atom to be of type <SPAN
1783
kinds of time atoms are supported depending on the
1785
CLASS="computeroutput"
1787
>: 4-byte signed integer
1788
and 8-byte double precision floating point atoms (the
1789
default ones). The meaning of the other parameters
1790
are the same as those in the <SAMP
1791
CLASS="computeroutput"
1797
>Time atoms have a special encoding in the HFD5 file.
1799
HREF="a6585.html#datatypesSupported"
1802
for more information on those types.
1808
>This class has two descendants:
1818
>Time32Atom(shape=1, flavor="numarray")</B
1822
>Define an atom of type <SAMP
1823
CLASS="computeroutput"
1829
>Time64Atom(shape=1, flavor="numarray")</B
1833
>Define an atom of type <SAMP
1834
CLASS="computeroutput"
1845
>EnumAtom(enum, dtype='UInt32', shape=1,
1846
flavor='numarray')</B
1852
>Description of an atom of an enumerated type.</P
1857
>Instances of this class describe the atom type used
1858
by an array to store enumerated values. Those
1859
values belong to an enumerated type.
1865
>The meaning of the <SAMP
1866
CLASS="computeroutput"
1870
CLASS="computeroutput"
1872
> arguments is the same as in
1874
CLASS="computeroutput"
1877
HREF="x4389.html#ColClassDescr"
1881
CLASS="computeroutput"
1884
CLASS="computeroutput"
1887
have the usual meaning of other <SAMP
1888
CLASS="computeroutput"
1892
CLASS="computeroutput"
1895
representation of concrete read values).
1901
>Enumerated atoms also have <SAMP
1902
CLASS="computeroutput"
1906
CLASS="computeroutput"
1908
> attributes with the same values as
1910
CLASS="computeroutput"
1920
>Now, there come two special classes,
1922
CLASS="computeroutput"
1925
CLASS="computeroutput"
1928
actually do not descend from <SAMP
1929
CLASS="computeroutput"
1932
which goal is so similar that they should be described
1933
here. The difference between them and the
1935
CLASS="computeroutput"
1937
> and descendants classes is that these
1938
special classes does not allow multidimensional atoms,
1939
nor multiple values per row. A <SPAN
1946
be specified neither as it is immutable (see below).
1956
only allowed to use these classes to create
1958
CLASS="computeroutput"
1960
> objects, not <SAMP
1961
CLASS="computeroutput"
1965
CLASS="computeroutput"
1978
>This class is meant to
1985
> kind of object in a row of an
1987
CLASS="computeroutput"
1991
CLASS="computeroutput"
1993
> behind the scenes. Due to the
1994
fact that you can not foresee how long will be the
1996
CLASS="computeroutput"
1999
(i.e. the atom already has a <SPAN
2006
length), you can only fit a representant of it per
2007
row. However, you can still pass several parameters to
2009
CLASS="computeroutput"
2010
>VLArray.append()</SAMP
2011
> method as they will
2012
be regarded as a <SPAN
2018
> of compound objects
2019
(the parameters), so that we still have only one
2020
object to be saved in a single row. It does not accept
2021
parameters and its flavor is automatically set to
2023
CLASS="computeroutput"
2025
>, so the reads of rows always
2026
returns an arbitrary python object.
2028
You can regard <SAMP
2029
CLASS="computeroutput"
2032
easy way to save an arbitrary number of generic python
2034
CLASS="computeroutput"
2045
>This class describes a
2053
CLASS="computeroutput"
2062
>. It differs from the
2064
CLASS="computeroutput"
2066
> class in that you can only add
2067
one instance of it to one specific row, i.e. the
2069
CLASS="computeroutput"
2070
>VLArray.append()</SAMP
2071
> method only accepts one
2072
object when the base atom is of this type. Besides, it
2073
supports Unicode strings (contrarily to
2075
CLASS="computeroutput"
2077
>) because it uses the UTF-8
2078
codification (this is why its <SAMP
2079
CLASS="computeroutput"
2082
method returns always 1) when serializing to disk. It
2083
does not accept any parameter and because its
2090
> is automatically set to
2092
CLASS="computeroutput"
2094
>, the reads of rows always
2095
returns a python string. See the <A
2096
HREF="x7045.html#VLArrayFormatDescr"
2099
curious on how this is implemented at the low-level.
2101
You can regard <SAMP
2102
CLASS="computeroutput"
2105
easy way to save generic variable length strings.
2112
CLASS="computeroutput"
2113
>examples/vlarray1.py</SAMP
2116
CLASS="computeroutput"
2117
>examples/vlarray2.py</SAMP
2118
> for further examples
2120
CLASS="computeroutput"
2122
>s, including object serialization
2123
and Unicode string management.
2133
SUMMARY="Footer navigation table"
b'\\ No newline at end of file'