~ubuntu-branches/ubuntu/natty/pytables/natty-updates

« back to all changes in this revision

Viewing changes to doc/html/x1268.html

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2006-06-28 10:45:03 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20060628104503-cc251q5o5j3e2k10
  * Fixed call to pyversions in debian/rules which failed on recent versions 
    of pyversions
  * Fixed clean rule in debian/rules which left the stamp files behind
  * Acknowledge NMU
  * Added Alexandre Fayolle to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>Dealing with nested structures in tables</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REL="HOME"
 
10
TITLE="PyTables User's Guide"
 
11
HREF="index.html"><LINK
 
12
REL="UP"
 
13
TITLE="Tutorials"
 
14
HREF="c514.html"><LINK
 
15
REL="PREVIOUS"
 
16
TITLE="Using enumerated types"
 
17
HREF="x1185.html"><LINK
 
18
REL="NEXT"
 
19
TITLE="Other examples in PyTables distribution"
 
20
HREF="x1376.html"></HEAD
 
21
><BODY
 
22
CLASS="sect1"
 
23
BGCOLOR="#FFFFFF"
 
24
TEXT="#000000"
 
25
LINK="#0000FF"
 
26
VLINK="#840084"
 
27
ALINK="#0000FF"
 
28
><DIV
 
29
CLASS="NAVHEADER"
 
30
><TABLE
 
31
SUMMARY="Header navigation table"
 
32
WIDTH="100%"
 
33
BORDER="0"
 
34
CELLPADDING="0"
 
35
CELLSPACING="0"
 
36
><TR
 
37
><TH
 
38
COLSPAN="3"
 
39
ALIGN="center"
 
40
><SPAN
 
41
CLASS="markup"
 
42
>PyTables</SPAN
 
43
> User's Guide: Hierarchical datasets in Python - Release 1.3.2</TH
 
44
></TR
 
45
><TR
 
46
><TD
 
47
WIDTH="10%"
 
48
ALIGN="left"
 
49
VALIGN="bottom"
 
50
><A
 
51
HREF="x1185.html"
 
52
ACCESSKEY="P"
 
53
>Prev</A
 
54
></TD
 
55
><TD
 
56
WIDTH="80%"
 
57
ALIGN="center"
 
58
VALIGN="bottom"
 
59
>Chapter 3. Tutorials</TD
 
60
><TD
 
61
WIDTH="10%"
 
62
ALIGN="right"
 
63
VALIGN="bottom"
 
64
><A
 
65
HREF="x1376.html"
 
66
ACCESSKEY="N"
 
67
>Next</A
 
68
></TD
 
69
></TR
 
70
></TABLE
 
71
><HR
 
72
ALIGN="LEFT"
 
73
WIDTH="100%"></DIV
 
74
><DIV
 
75
CLASS="sect1"
 
76
><H1
 
77
CLASS="sect1"
 
78
><A
 
79
NAME="section3.7"
 
80
>3.7. Dealing with nested structures in tables</A
 
81
></H1
 
82
><P
 
83
>PyTables supports the handling of nested structures (or
 
84
          nested datatypes, as you prefer) in table objects, allowing
 
85
          you to define arbitrarily nested columns.
 
86
        </P
 
87
><P
 
88
>An example will clarify what this means. Let's suppose
 
89
          that you want to group your data in pieces of information
 
90
          that are more related than others pieces in your table, So
 
91
          you may want to tie them up together in order to have your
 
92
          table better structured but also be able to retrieve and
 
93
          deal with these groups more easily.
 
94
        </P
 
95
><P
 
96
>You can create such a nested substructures by just nesting
 
97
          subclasses of <SAMP
 
98
CLASS="computeroutput"
 
99
>IsDescription</SAMP
 
100
>. Let's see one
 
101
          example (okay, it's a bit silly, but will serve for
 
102
          demonstration purposes):
 
103
        </P
 
104
><PRE
 
105
CLASS="screen"
 
106
>&#13;class Info(IsDescription):
 
107
    """A sub-structure of Test"""
 
108
    _v_pos = 2   # The position in the whole structure
 
109
    name = StringCol(10)
 
110
    value = Float64Col(pos=0)
 
111
 
 
112
colors = Enum(['red', 'green', 'blue'])  # An enumerated type
 
113
 
 
114
class NestedDescr(IsDescription):
 
115
    """A description that has several nested columns"""
 
116
    color = EnumCol(colors, 'red', dtype='UInt32', indexed=1) # indexed column
 
117
    info1 = Info()
 
118
    class info2(IsDescription):
 
119
        _v_pos = 1
 
120
        name = StringCol(10)
 
121
        value = Float64Col(pos=0)
 
122
        class info3(IsDescription):
 
123
            x = FloatCol(1)
 
124
            y = UInt8Col(1)
 
125
 
 
126
        </PRE
 
127
><P
 
128
>The root class is <SAMP
 
129
CLASS="computeroutput"
 
130
>NestedDescr</SAMP
 
131
> and both
 
132
          <SAMP
 
133
CLASS="computeroutput"
 
134
>info1</SAMP
 
135
> and <SAMP
 
136
CLASS="computeroutput"
 
137
>info2</SAMP
 
138
> are
 
139
          <SPAN
 
140
CLASS="emphasis"
 
141
><I
 
142
CLASS="emphasis"
 
143
>substructures</I
 
144
></SPAN
 
145
> of it. Note how <SAMP
 
146
CLASS="computeroutput"
 
147
>info1</SAMP
 
148
> is
 
149
          actually an instance of the class <SAMP
 
150
CLASS="computeroutput"
 
151
>Info</SAMP
 
152
> that was
 
153
          defined prior to <SAMP
 
154
CLASS="computeroutput"
 
155
>NestedDescr</SAMP
 
156
>. Also, there is a
 
157
          third substructure, namely <SAMP
 
158
CLASS="computeroutput"
 
159
>info3</SAMP
 
160
> that hangs
 
161
          from the substructure <SAMP
 
162
CLASS="computeroutput"
 
163
>info2</SAMP
 
164
>. You can also
 
165
          define positions of substructures in the containing object
 
166
          by declaring the special class attribute
 
167
          <SAMP
 
168
CLASS="computeroutput"
 
169
>_v_pos</SAMP
 
170
>.
 
171
        </P
 
172
><DIV
 
173
CLASS="sect2"
 
174
><H2
 
175
CLASS="sect2"
 
176
><A
 
177
NAME="subsection3.7.1"
 
178
>3.7.1. Nested table creation</A
 
179
></H2
 
180
><P
 
181
>Now that we have defined our nested structure, let's
 
182
            create a <SPAN
 
183
CLASS="emphasis"
 
184
><I
 
185
CLASS="emphasis"
 
186
>nested</I
 
187
></SPAN
 
188
> table, that is a table with
 
189
            columns that contain other subcolumns.
 
190
          </P
 
191
><PRE
 
192
CLASS="screen"
 
193
>&#13;&#62;&#62;&#62; from tables import *
 
194
&#62;&#62;&#62; fileh = openFile("nested-tut.h5", "w")
 
195
&#62;&#62;&#62; table = fileh.createTable(fileh.root, 'table', NestedDescr)
 
196
&#62;&#62;&#62;
 
197
          </PRE
 
198
><P
 
199
>Done! Now, we have to feed the table with some
 
200
            values. The problem is how we are going to reference to
 
201
            the nested fields. That's easy, just use a
 
202
            <SAMP
 
203
CLASS="computeroutput"
 
204
>'/'</SAMP
 
205
> character to separate names in different
 
206
            nested levels. Look at this:
 
207
          </P
 
208
><PRE
 
209
CLASS="screen"
 
210
>&#13;&#62;&#62;&#62; for i in range(10):
 
211
...     row['color'] = colors[['red', 'green', 'blue'][i%3]]
 
212
...     row['info1/name'] = "name1-%s" % i
 
213
...     row['info2/name'] = "name2-%s" % i
 
214
...     row['info2/info3/y'] =  i
 
215
...     # All the rest will be filled with defaults
 
216
...     row.append()
 
217
...
 
218
&#62;&#62;&#62; table.flush()
 
219
&#62;&#62;&#62; table.nrows
 
220
10L
 
221
&#62;&#62;&#62;
 
222
          </PRE
 
223
><P
 
224
>You see? In order to fill the fields located in the
 
225
            substructures, we just need to specify its full path
 
226
            in the table hierarchy.
 
227
          </P
 
228
></DIV
 
229
><DIV
 
230
CLASS="sect2"
 
231
><H2
 
232
CLASS="sect2"
 
233
><A
 
234
NAME="subsection3.7.2"
 
235
>3.7.2. Reading nested tables: introducing <SPAN
 
236
CLASS="markup"
 
237
>NestedRecArray</SPAN
 
238
> objects</A
 
239
></H2
 
240
><P
 
241
>Now, what happens if we want to read the table? Which
 
242
            data container will be used to keep the data? Well, it's
 
243
            worth trying it:
 
244
          </P
 
245
><PRE
 
246
CLASS="screen"
 
247
>&#13;&#62;&#62;&#62; nra = table[::4]
 
248
&#62;&#62;&#62; print nra
 
249
NestedRecArray[
 
250
(((1.0, 0), 'name2-0', 0.0), ('name1-0', 0.0), 0L),
 
251
(((1.0, 4), 'name2-4', 0.0), ('name1-4', 0.0), 1L),
 
252
(((1.0, 8), 'name2-8', 0.0), ('name1-8', 0.0), 2L)
 
253
]
 
254
&#62;&#62;&#62;
 
255
          </PRE
 
256
><P
 
257
>We have read one row for each four in the table, giving a
 
258
            result of three rows. What about the container? Well, we
 
259
            can see that it is a new mysterious object known as
 
260
            <SAMP
 
261
CLASS="computeroutput"
 
262
>NestedRecArray</SAMP
 
263
>. If we ask for more info on
 
264
            that:
 
265
          </P
 
266
><PRE
 
267
CLASS="screen"
 
268
>&#13;&#62;&#62;&#62; type(nra)
 
269
&#60;class 'tables.nestedrecords.NestedRecArray'&#62;
 
270
          </PRE
 
271
><P
 
272
>we see that it is an instance of the class
 
273
            <SAMP
 
274
CLASS="computeroutput"
 
275
>NestedRecArray</SAMP
 
276
> that lives in the module
 
277
            <SAMP
 
278
CLASS="computeroutput"
 
279
>nestedrecords</SAMP
 
280
> of <SAMP
 
281
CLASS="computeroutput"
 
282
>tables</SAMP
 
283
>
 
284
            package. <SAMP
 
285
CLASS="computeroutput"
 
286
>NestedRecArray</SAMP
 
287
> is actually a
 
288
            subclass of the <SAMP
 
289
CLASS="computeroutput"
 
290
>RecArray</SAMP
 
291
> object of the
 
292
            <SAMP
 
293
CLASS="computeroutput"
 
294
>records</SAMP
 
295
> module of <SAMP
 
296
CLASS="computeroutput"
 
297
>numarray</SAMP
 
298
>
 
299
            package. You can see more info about
 
300
            <SAMP
 
301
CLASS="computeroutput"
 
302
>NestedRecArray</SAMP
 
303
> object in <A
 
304
HREF="a6736.html#NestedRecArrayClassDescr"
 
305
>appendix�B</A
 
306
>.
 
307
          </P
 
308
><P
 
309
>You can make use of the above object in many different
 
310
            ways. For example, you can use it to append new data to
 
311
            the existing table object:
 
312
          </P
 
313
><PRE
 
314
CLASS="screen"
 
315
>&#13;&#62;&#62;&#62; table.append(nra)
 
316
&#62;&#62;&#62; table.nrows
 
317
13L
 
318
&#62;&#62;&#62;
 
319
          </PRE
 
320
><P
 
321
>Or, to create new tables:
 
322
          </P
 
323
><PRE
 
324
CLASS="screen"
 
325
>&#13;&#62;&#62;&#62; table2 = fileh.createTable(fileh.root, 'table2', nra)
 
326
&#62;&#62;&#62; table2[:]
 
327
array(
 
328
[(((1.0, 0), 'name2-0', 0.0), ('name1-0', 0.0), 0L),
 
329
(((1.0, 4), 'name2-4', 0.0), ('name1-4', 0.0), 1L),
 
330
(((1.0, 8), 'name2-8', 0.0), ('name1-8', 0.0), 2L)],
 
331
descr=[('info2', [('info3', [('x', '1f8'), ('y', '1u1')]), ('name',
 
332
 '1a10'), ('value', '1f8')]), ('info1', [('name', '1a10'), ('value',
 
333
 '1f8')]), ('color', '1u4')], shape=3)
 
334
          </PRE
 
335
><P
 
336
>Finally, we can select nested values that fulfill some
 
337
            condition:
 
338
          </P
 
339
><PRE
 
340
CLASS="screen"
 
341
>&#13;&#62;&#62;&#62; names = [ x['info2/name'] for x in table if x['color'] == colors.red ]
 
342
&#62;&#62;&#62; names
 
343
['name2-0', 'name2-3', 'name2-6', 'name2-9', 'name2-0']
 
344
&#62;&#62;&#62;
 
345
          </PRE
 
346
><P
 
347
>Note that the row accessor does not provide the natural
 
348
            naming feature, so you have to completely specify the path
 
349
            of your desired columns in order to reach them.
 
350
          </P
 
351
></DIV
 
352
><DIV
 
353
CLASS="sect2"
 
354
><H2
 
355
CLASS="sect2"
 
356
><A
 
357
NAME="subsection3.7.3"
 
358
>3.7.3. Using Cols accessor</A
 
359
></H2
 
360
><P
 
361
>We can use the <SAMP
 
362
CLASS="computeroutput"
 
363
>cols</SAMP
 
364
> attribute object (see
 
365
            <A
 
366
HREF="x3528.html#ColsClassDescr"
 
367
>4.7</A
 
368
>) of the table so as to
 
369
            quickly access the info located in the interesting
 
370
            substructures:
 
371
          </P
 
372
><PRE
 
373
CLASS="screen"
 
374
>&#13;&#62;&#62;&#62; table.cols.info2[1:5]
 
375
array(
 
376
[((1.0, 1), 'name2-1', 0.0),
 
377
((1.0, 2), 'name2-2', 0.0),
 
378
((1.0, 3), 'name2-3', 0.0),
 
379
((1.0, 4), 'name2-4', 0.0)],
 
380
descr=[('info3', [('x', '1f8'), ('y', '1u1')]), ('name', '1a10'),
 
381
 ('value', '1f8')],
 
382
shape=4)
 
383
&#62;&#62;&#62;
 
384
          </PRE
 
385
><P
 
386
>Here, we have made use of the cols accessor to access to
 
387
            the <SPAN
 
388
CLASS="emphasis"
 
389
><I
 
390
CLASS="emphasis"
 
391
>info2</I
 
392
></SPAN
 
393
> substructure and an slice operation to
 
394
            get access to the subset of data we were interested in;
 
395
            you probably have recognized the natural naming approach
 
396
            here. We can continue and ask for data in <SPAN
 
397
CLASS="emphasis"
 
398
><I
 
399
CLASS="emphasis"
 
400
>info3</I
 
401
></SPAN
 
402
>
 
403
            substructure:
 
404
          </P
 
405
><PRE
 
406
CLASS="screen"
 
407
>&#13;&#62;&#62;&#62; table.cols.info2.info3[1:5]
 
408
array(
 
409
[(1.0, 1),
 
410
(1.0, 2),
 
411
(1.0, 3),
 
412
(1.0, 4)],
 
413
descr=[('x', '1f8'), ('y', '1u1')],
 
414
shape=4)
 
415
&#62;&#62;&#62;
 
416
          </PRE
 
417
><P
 
418
>You can also use the <SAMP
 
419
CLASS="computeroutput"
 
420
>_f_col</SAMP
 
421
> method to get a
 
422
            handler for a column:
 
423
          </P
 
424
><PRE
 
425
CLASS="screen"
 
426
>&#13;&#62;&#62;&#62; table.cols._f_col('info2')
 
427
/table.cols.info2 (Cols), 3 columns
 
428
  info3 (Cols(1,), Description)
 
429
  name (Column(1,), CharType)
 
430
  value (Column(1,), Float64)
 
431
          </PRE
 
432
><P
 
433
>Here, you've got another <SAMP
 
434
CLASS="computeroutput"
 
435
>Cols</SAMP
 
436
> object handler
 
437
            because <SPAN
 
438
CLASS="emphasis"
 
439
><I
 
440
CLASS="emphasis"
 
441
>info2</I
 
442
></SPAN
 
443
> was a nested column. If you select
 
444
            a non-nested column, you will get a regular
 
445
            <SAMP
 
446
CLASS="computeroutput"
 
447
>Column</SAMP
 
448
> instance:
 
449
          </P
 
450
><PRE
 
451
CLASS="screen"
 
452
>&#13;&#62;&#62;&#62; ycol = table.cols._f_col('info2/info3/y')
 
453
&#62;&#62;&#62; ycol
 
454
/table.cols.info2.info3.y (Column(1,), UInt8, idx=None)
 
455
&#62;&#62;&#62;
 
456
          </PRE
 
457
><P
 
458
>To sum up, the <SAMP
 
459
CLASS="computeroutput"
 
460
>cols</SAMP
 
461
> accessor is a very handy
 
462
            and powerful way to access data in your nested tables. Be
 
463
            sure of using it, specially when doing interactive work.
 
464
          </P
 
465
></DIV
 
466
><DIV
 
467
CLASS="sect2"
 
468
><H2
 
469
CLASS="sect2"
 
470
><A
 
471
NAME="subsection3.7.4"
 
472
>3.7.4. Accessing meta-information of nested
 
473
            tables</A
 
474
></H2
 
475
><P
 
476
>Tables have an attribute called <SAMP
 
477
CLASS="computeroutput"
 
478
>description</SAMP
 
479
>
 
480
            which points to an instance of the
 
481
            <SAMP
 
482
CLASS="computeroutput"
 
483
>Description</SAMP
 
484
> class (see <A
 
485
HREF="x3623.html#DescriptionClassDescr"
 
486
>4.8</A
 
487
>) and is useful to
 
488
            discover different meta-information about table
 
489
            data.
 
490
          </P
 
491
><P
 
492
>Let's see how it looks like:
 
493
          </P
 
494
><PRE
 
495
CLASS="screen"
 
496
>&#13;&#62;&#62;&#62; table.description
 
497
{
 
498
  "info2": {
 
499
    "info3": {
 
500
      "x": FloatCol(dflt=1, shape=1, itemsize=8, pos=0, indexed=False),
 
501
      "y": UInt8Col(dflt=1, shape=1, pos=1, indexed=False)},
 
502
    "name": StringCol(length=10, dflt=None, shape=1, pos=1, indexed=False),
 
503
    "value": Float64Col(dflt=0.0, shape=1, pos=2, indexed=False)},
 
504
  "info1": {
 
505
    "name": StringCol(length=10, dflt=None, shape=1, pos=0, indexed=False),
 
506
    "value": Float64Col(dflt=0.0, shape=1, pos=1, indexed=False)},
 
507
  "color": EnumCol(Enum({'blue': 2, 'green': 1, 'red': 0}), 'red',
 
508
 dtype='UInt32', shape=1, pos=2, indexed=1)}
 
509
&#62;&#62;&#62;
 
510
          </PRE
 
511
><P
 
512
>As you can see, it provides very useful information on
 
513
            both the formats and the structure of the columns in your
 
514
            table.
 
515
          </P
 
516
><P
 
517
>This object also provides a natural naming approach to
 
518
            access to subcolumns metadata:
 
519
          </P
 
520
><PRE
 
521
CLASS="screen"
 
522
>&#13;&#62;&#62;&#62; table.description.info1
 
523
{
 
524
    "name": StringCol(length=10, dflt=None, shape=1, pos=0, indexed=False),
 
525
    "value": Float64Col(dflt=0.0, shape=1, pos=1, indexed=False)}
 
526
&#62;&#62;&#62; table.description.info2.info3
 
527
{
 
528
      "x": FloatCol(dflt=1, shape=1, itemsize=8, pos=0, indexed=False),
 
529
      "y": UInt8Col(dflt=1, shape=1, pos=1, indexed=False)}
 
530
&#62;&#62;&#62;
 
531
          </PRE
 
532
><P
 
533
>There are other variables that can be interesting for you:
 
534
          </P
 
535
><PRE
 
536
CLASS="screen"
 
537
>&#13;&#62;&#62;&#62; table.description._v_nestedNames
 
538
[('info2', [('info3', ['x', 'y']), 'name', 'value']), ('info1',
 
539
 ['name', 'value']), 'color']
 
540
&#62;&#62;&#62; table.description.info1._v_nestedNames
 
541
['name', 'value']
 
542
&#62;&#62;&#62;
 
543
          </PRE
 
544
><P
 
545
><SAMP
 
546
CLASS="computeroutput"
 
547
>_v_nestedNames</SAMP
 
548
> provides the names of the
 
549
            columns as well as its structure. You can see that there
 
550
            are the same attributes for the different levels of the
 
551
            <SAMP
 
552
CLASS="computeroutput"
 
553
>Description</SAMP
 
554
> object, because the levels are
 
555
            <SPAN
 
556
CLASS="emphasis"
 
557
><I
 
558
CLASS="emphasis"
 
559
>also</I
 
560
></SPAN
 
561
> <SAMP
 
562
CLASS="computeroutput"
 
563
>Description</SAMP
 
564
> objects themselves.
 
565
          </P
 
566
><P
 
567
>There is a special attribute, called
 
568
            <SAMP
 
569
CLASS="computeroutput"
 
570
>_v_nestedDescr</SAMP
 
571
> that can be useful to create
 
572
            <SAMP
 
573
CLASS="computeroutput"
 
574
>NestedRecArrays</SAMP
 
575
> objects that imitate the
 
576
            structure of the table (or a subtable!):
 
577
          </P
 
578
><PRE
 
579
CLASS="screen"
 
580
>&#13;&#62;&#62;&#62; from tables import nestedrecords
 
581
&#62;&#62;&#62; table.description._v_nestedDescr
 
582
[('info2', [('info3', [('x', '1f8'), ('y', '1u1')]), ('name', '1a10'),
 
583
 ('value', '1f8')]), ('info1', [('name', '1a10'), ('value', '1f8')]),
 
584
 ('color', '1u4')]
 
585
&#62;&#62;&#62; nestedrecords.array(None, descr=table.description._v_nestedDescr)
 
586
array(
 
587
[],
 
588
descr=[('info2', [('info3', [('x', '1f8'), ('y', '1u1')]), ('name',
 
589
 '1a10'), ('value', '1f8')]), ('info1', [('name', '1a10'), ('value',
 
590
 '1f8')]),('color', '1u4')], shape=0)
 
591
&#62;&#62;&#62; nestedrecords.array(None, descr=table.description.info2._v_nestedDescr)
 
592
array(
 
593
[],
 
594
descr=[('info3', [('x', '1f8'), ('y', '1u1')]), ('name', '1a10'),
 
595
('value', '1f8')], shape=0)
 
596
&#62;&#62;&#62;
 
597
          </PRE
 
598
><P
 
599
>Look the section <A
 
600
HREF="x3623.html#DescriptionClassDescr"
 
601
>4.8</A
 
602
>
 
603
            for the complete listing of attributes.
 
604
          </P
 
605
><P
 
606
>Finally, there is a special iterator of the
 
607
            <SAMP
 
608
CLASS="computeroutput"
 
609
>Description</SAMP
 
610
> class, called <SAMP
 
611
CLASS="computeroutput"
 
612
>_v_walk</SAMP
 
613
>
 
614
            that is able to return you the different columns of the
 
615
            table:
 
616
          </P
 
617
><PRE
 
618
CLASS="screen"
 
619
>&#13;&#62;&#62;&#62; for coldescr in table.description._v_walk():
 
620
...     print "column--&#62;",coldescr
 
621
...
 
622
column--&#62; Description([('info2', [('info3', [('x', '1f8'), ('y',
 
623
 '1u1')]), ('name', '1a10'), ('value', '1f8')]), ('info1', [('name',
 
624
 '1a10'), ('value', '1f8')]), ('color', '1u4')])
 
625
column--&#62; EnumCol(Enum({'blue': 2, 'green': 1, 'red': 0}), 'red',
 
626
 dtype='UInt32', shape=1, pos=2, indexed=1)
 
627
column--&#62; Description([('info3', [('x', '1f8'), ('y', '1u1')]),
 
628
 ('name', '1a10'), ('value', '1f8')])
 
629
column--&#62; StringCol(length=10, dflt=None, shape=1, pos=1, indexed=False)
 
630
column--&#62; Float64Col(dflt=0.0, shape=1, pos=2, indexed=False)
 
631
column--&#62; Description([('name', '1a10'), ('value', '1f8')])
 
632
column--&#62; StringCol(length=10, dflt=None, shape=1, pos=0, indexed=False)
 
633
column--&#62; Float64Col(dflt=0.0, shape=1, pos=1, indexed=False)
 
634
column--&#62; Description([('x', '1f8'), ('y', '1u1')])
 
635
column--&#62; FloatCol(dflt=1, shape=1, itemsize=8, pos=0, indexed=False)
 
636
column--&#62; UInt8Col(dflt=1, shape=1, pos=1, indexed=False)
 
637
&#62;&#62;&#62;
 
638
          </PRE
 
639
><P
 
640
>Well, this is the end of this tutorial. As always, do not
 
641
          forget to close your files:
 
642
          </P
 
643
><PRE
 
644
CLASS="screen"
 
645
>&#13;&#62;&#62;&#62; fileh.close()
 
646
&#62;&#62;&#62;
 
647
          </PRE
 
648
><P
 
649
>Finally, you may want to have a look at your resulting
 
650
            data file:
 
651
          </P
 
652
><PRE
 
653
CLASS="screen"
 
654
>&#13;$ ptdump -d nested-tut.h5
 
655
/ (RootGroup) ''
 
656
/table (Table(13L,)) ''
 
657
  Data dump:
 
658
[0] (((1.0, 0), 'name2-0', 0.0), ('name1-0', 0.0), 0L)
 
659
[1] (((1.0, 1), 'name2-1', 0.0), ('name1-1', 0.0), 1L)
 
660
[2] (((1.0, 2), 'name2-2', 0.0), ('name1-2', 0.0), 2L)
 
661
[3] (((1.0, 3), 'name2-3', 0.0), ('name1-3', 0.0), 0L)
 
662
[4] (((1.0, 4), 'name2-4', 0.0), ('name1-4', 0.0), 1L)
 
663
[5] (((1.0, 5), 'name2-5', 0.0), ('name1-5', 0.0), 2L)
 
664
[6] (((1.0, 6), 'name2-6', 0.0), ('name1-6', 0.0), 0L)
 
665
[7] (((1.0, 7), 'name2-7', 0.0), ('name1-7', 0.0), 1L)
 
666
[8] (((1.0, 8), 'name2-8', 0.0), ('name1-8', 0.0), 2L)
 
667
[9] (((1.0, 9), 'name2-9', 0.0), ('name1-9', 0.0), 0L)
 
668
[10] (((1.0, 0), 'name2-0', 0.0), ('name1-0', 0.0), 0L)
 
669
[11] (((1.0, 4), 'name2-4', 0.0), ('name1-4', 0.0), 1L)
 
670
[12] (((1.0, 8), 'name2-8', 0.0), ('name1-8', 0.0), 2L)
 
671
/table2 (Table(3L,)) ''
 
672
  Data dump:
 
673
[0] (((1.0, 0), 'name2-0', 0.0), ('name1-0', 0.0), 0L)
 
674
[1] (((1.0, 4), 'name2-4', 0.0), ('name1-4', 0.0), 1L)
 
675
[2] (((1.0, 8), 'name2-8', 0.0), ('name1-8', 0.0), 2L)
 
676
          </PRE
 
677
><P
 
678
>Most of the code in this section is also available in
 
679
              <SAMP
 
680
CLASS="computeroutput"
 
681
>examples/nested-tut.py</SAMP
 
682
>.
 
683
            </P
 
684
><P
 
685
>All in all, <SAMP
 
686
CLASS="computeroutput"
 
687
>PyTables</SAMP
 
688
> provides a quite
 
689
              comprehensive toolset to cope with nested structures and
 
690
              address your classification needs. However, caveat
 
691
              emptor, be sure to not nest your data too deeply or you
 
692
              will get inevitably messed interpreting too intertwined
 
693
              lists, tuples and description objects.
 
694
            </P
 
695
></DIV
 
696
></DIV
 
697
><DIV
 
698
CLASS="NAVFOOTER"
 
699
><HR
 
700
ALIGN="LEFT"
 
701
WIDTH="100%"><TABLE
 
702
SUMMARY="Footer navigation table"
 
703
WIDTH="100%"
 
704
BORDER="0"
 
705
CELLPADDING="0"
 
706
CELLSPACING="0"
 
707
><TR
 
708
><TD
 
709
WIDTH="33%"
 
710
ALIGN="left"
 
711
VALIGN="top"
 
712
><A
 
713
HREF="x1185.html"
 
714
ACCESSKEY="P"
 
715
>Prev</A
 
716
></TD
 
717
><TD
 
718
WIDTH="34%"
 
719
ALIGN="center"
 
720
VALIGN="top"
 
721
><A
 
722
HREF="index.html"
 
723
ACCESSKEY="H"
 
724
>Home</A
 
725
></TD
 
726
><TD
 
727
WIDTH="33%"
 
728
ALIGN="right"
 
729
VALIGN="top"
 
730
><A
 
731
HREF="x1376.html"
 
732
ACCESSKEY="N"
 
733
>Next</A
 
734
></TD
 
735
></TR
 
736
><TR
 
737
><TD
 
738
WIDTH="33%"
 
739
ALIGN="left"
 
740
VALIGN="top"
 
741
>Using enumerated types</TD
 
742
><TD
 
743
WIDTH="34%"
 
744
ALIGN="center"
 
745
VALIGN="top"
 
746
><A
 
747
HREF="c514.html"
 
748
ACCESSKEY="U"
 
749
>Up</A
 
750
></TD
 
751
><TD
 
752
WIDTH="33%"
 
753
ALIGN="right"
 
754
VALIGN="top"
 
755
>Other examples in PyTables distribution</TD
 
756
></TR
 
757
></TABLE
 
758
></DIV
 
759
></BODY
 
760
></HTML
 
761
>
 
 
b'\\ No newline at end of file'