4.12. The EArray class

This is a child of the Array class (see 4.10) and as such, EArray represents an array on the file. The difference is that EArray allows to enlarge datasets along any single dimension[1] you select. Another important difference is that it also supports compression.

So, in addition to the attributes and methods that EArray inherits from Array, it supports a few more that provide a way to enlarge the arrays on disk. Following are described the new variables and methods as well as some that already exist in Array but that differ somewhat on the meaning and/or functionality in the EArray context.

4.12.1. EArray instance variables

atom

An Atom (see 4.16.3) instance representing the shape, type and flavor of the atomic objects to be saved. One of the dimensions of the shape is 0, meaning that the array can be extended along it.

extdim

The enlargeable dimension, i.e. the dimension this array can be extended along.

nrows

The length of the enlargeable dimension of the array.

4.12.2. EArray methods

4.12.2.1. getEnum()

Get the enumerated type associated with this array.

If this array is of an enumerated type, the corresponding Enum instance (see 4.17.4) is returned. If it is not of an enumerated type, a TypeError is raised.

4.12.2.2. append(sequence)

Appends a sequence to the underlying dataset. Obviously, this sequence must have the same type as the EArray instance; otherwise a TypeError is issued. In the same way, the dimensions of the sequence have to conform to those of EArray, that is, all the dimensions have to be the same except, of course, that of the enlargeable dimension which can be of any length (even 0!).

Example of use (code available in examples/earray1.py):


import tables
from numarray import strings

fileh = tables.openFile("earray1.h5", mode = "w")
a = tables.StringAtom(shape=(0,), length=8)
# Use 'a' as the object type for the enlargeable array
array_c = fileh.createEArray(fileh.root, 'array_c', a, "Chars")
array_c.append(strings.array(['a'*2, 'b'*4], itemsize=8))
array_c.append(strings.array(['a'*6, 'b'*8, 'c'*10], itemsize=8))

# Read the string EArray we have created on disk
for s in array_c:
    print "array_c[%s] => '%s'" % (array_c.nrow, s)
# Close the file
fileh.close()
	      

and the output is:


		array_c[0] => 'aa'
		array_c[1] => 'bbbb'
		array_c[2] => 'aaaaaa'
		array_c[3] => 'bbbbbbbb'
		array_c[4] => 'cccccccc'
	      

Notes

[1]

In the future, multiple enlargeable dimensions might be implemented as well.