This section describes some classes that do not fit in any other section and that mainly serve for ancillary purposes.
Container for filter properties.
This class is meant to serve as a container that keeps information about the filter properties associated with the chunked leaves, that is Table, CArray, EArray and VLArray.
Instances of this class can be directly compared for equality.
Parameters : | complevel : int
complib : str
shuffle : bool
fletcher32 : bool
|
---|
Examples
This is a small example on using the Filters class:
import numpy
from tables import *
fileh = open_file('test5.h5', mode='w')
atom = Float32Atom()
filters = Filters(complevel=1, complib='blosc', fletcher32=True)
arr = fileh.create_earray(fileh.root, 'earray', atom, (0,2),
"A growable array", filters=filters)
# Append several rows in only one call
arr.append(numpy.array([[1., 2.],
[2., 3.],
[3., 4.]], dtype=numpy.float32))
# Print information on that enlargeable array
print("Result Array:")
print(repr(arr))
fileh.close()
This enforces the use of the Blosc library, a compression level of 1 and a Fletcher32 checksum filter as well. See the output of this example:
Result Array:
/earray (EArray(3, 2), fletcher32, shuffle, blosc(1)) 'A growable array'
type = float32
shape = (3, 2)
itemsize = 4
nrows = 3
extdim = 0
flavor = 'numpy'
byteorder = 'little'
Filters attributes
Whether the Fletcher32 filter is active or not.
The compression level (0 disables compression).
The compression filter used (irrelevant when compression is not enabled).
Whether the Shuffle filter is active or not.
Get a copy of the filters, possibly overriding some arguments.
Constructor arguments to be overridden must be passed as keyword arguments.
Using this method is recommended over replacing the attributes of an instance, since instances of this class may become immutable in the future:
>>> filters1 = Filters()
>>> filters2 = filters1.copy()
>>> filters1 == filters2
True
>>> filters1 is filters2
False
>>> filters3 = filters1.copy(complevel=1)
Traceback (most recent call last):
...
ValueError: compression library ``None`` is not supported...
>>> filters3 = filters1.copy(complevel=1, complib='zlib')
>>> print(filters1)
Filters(complevel=0, shuffle=False, fletcher32=False)
>>> print(filters3)
Filters(complevel=1, complib='zlib', shuffle=False, fletcher32=False)
>>> filters1.copy(foobar=42)
Traceback (most recent call last):
...
TypeError: __init__() got an unexpected keyword argument 'foobar'
Represents the index of a column in a table.
This class is used to keep the indexing information for columns in a Table dataset (see The Table class). It is actually a descendant of the Group class (see The Group class), with some added functionality. An Index is always associated with one and only one column in the table.
Note
This class is mainly intended for internal use, but some of its documented attributes and methods may be interesting for the programmer.
Parameters : | parentnode :
name : str
atom : Atom
title :
kind :
optlevel :
filters : Filters
tmp_dir :
expectedrows :
byteorder :
blocksizes :
|
---|
The Column (see The Column class) instance for the indexed column.
Whether the index is dirty or not.
Dirty indexes are out of sync with column data, so they exist but they are not usable.
Filter properties for this index - see Filters in The Filters class.
Whether the index is completely sorted or not.
Changed in version 3.0: The is_CSI property has been renamed into is_csi.
The number of currently indexed rows for this column.
Return the sorted values of index in the specified range.
The meaning of the start, stop and step arguments is the same as in Table.read_sorted().
Return the indices values of index in the specified range.
The meaning of the start, stop and step arguments is the same as in Table.read_sorted().
Return the indices values of index in the specified range.
If key argument is an integer, the corresponding index is returned. If key is a slice, the range of indices determined by it is returned. A negative value of step in slice is supported, meaning that the results will be returned in reverse order.
This method is equivalent to Index.read_indices().
Represent the index (sorted or reverse index) dataset in HDF5 file.
All NumPy typecodes are supported except for complex datatypes.
Parameters : | parentnode :
name : str
atom :
title :
filters : Filters
byteorder :
|
---|
The chunksize for this object.
The slicesize for this object.
Enumerated type.
Each instance of this class represents an enumerated type. The values of the type must be declared exhaustively and named with strings, and they might be given explicit concrete values, though this is not compulsory. Once the type is defined, it can not be modified.
There are three ways of defining an enumerated type. Each one of them corresponds to the type of the only argument in the constructor of Enum:
Sequence of names: each enumerated value is named using a string, and its order is determined by its position in the sequence; the concrete value is assigned automatically:
>>> boolEnum = Enum(['True', 'False'])
Mapping of names: each enumerated value is named by a string and given an explicit concrete value. All of the concrete values must be different, or a ValueError will be raised:
>>> priority = Enum({'red': 20, 'orange': 10, 'green': 0})
>>> colors = Enum({'red': 1, 'blue': 1})
Traceback (most recent call last):
...
ValueError: enumerated values contain duplicate concrete values: 1
Enumerated type: in that case, a copy of the original enumerated type is created. Both enumerated types are considered equal:
>>> prio2 = Enum(priority)
>>> priority == prio2
True
Please note that names starting with _ are not allowed, since they are reserved for internal usage:
>>> prio2 = Enum(['_xx'])
Traceback (most recent call last):
...
ValueError: name of enumerated value can not start with ``_``: '_xx'
The concrete value of an enumerated value is obtained by getting its name as an attribute of the Enum instance (see __getattr__()) or as an item (see __getitem__()). This allows comparisons between enumerated values and assigning them to ordinary Python variables:
>>> redv = priority.red
>>> redv == priority['red']
True
>>> redv > priority.green
True
>>> priority.red == priority.orange
False
The name of the enumerated value corresponding to a concrete value can also be obtained by using the __call__() method of the enumerated type. In this way you get the symbolic name to use it later with __getitem__():
>>> priority(redv)
'red'
>>> priority.red == priority[priority(priority.red)]
True
(If you ask, the __getitem__() method is not used for this purpose to avoid ambiguity in the case of using strings as concrete values.)
Get the name of the enumerated value with that concrete value.
If there is no value with that concrete value in the enumeration and a second argument is given as a default, this is returned. Else, a ValueError is raised.
This method can be used for checking that a concrete value belongs to the set of concrete values in an enumerated type.
Examples
Let enum be an enumerated type defined as:
>>> enum = Enum({'T0': 0, 'T1': 2, 'T2': 5})
then:
>>> enum(5)
'T2'
>>> enum(42, None) is None
True
>>> enum(42)
Traceback (most recent call last):
...
ValueError: no enumerated value with that concrete value: 42
Is there an enumerated value with that name in the type?
If the enumerated type has an enumerated value with that name, True is returned. Otherwise, False is returned. The name must be a string.
This method does not check for concrete values matching a value in an enumerated type. For that, please use the Enum.__call__() method.
Examples
Let enum be an enumerated type defined as:
>>> enum = Enum({'T0': 0, 'T1': 2, 'T2': 5})
then:
>>> 'T1' in enum
True
>>> 'foo' in enum
False
>>> 0 in enum
Traceback (most recent call last):
...
TypeError: name of enumerated value is not a string: 0
>>> enum.T1 in enum # Be careful with this!
Traceback (most recent call last):
...
TypeError: name of enumerated value is not a string: 2
Is the other enumerated type equivalent to this one?
Two enumerated types are equivalent if they have exactly the same enumerated values (i.e. with the same names and concrete values).
Examples
Let enum* be enumerated types defined as:
>>> enum1 = Enum({'T0': 0, 'T1': 2})
>>> enum2 = Enum(enum1)
>>> enum3 = Enum({'T1': 2, 'T0': 0})
>>> enum4 = Enum({'T0': 0, 'T1': 2, 'T2': 5})
>>> enum5 = Enum({'T0': 0})
>>> enum6 = Enum({'T0': 10, 'T1': 20})
then:
>>> enum1 == enum1
True
>>> enum1 == enum2 == enum3
True
>>> enum1 == enum4
False
>>> enum5 == enum1
False
>>> enum1 == enum6
False
Comparing enumerated types with other kinds of objects produces a false result:
>>> enum1 == {'T0': 0, 'T1': 2}
False
>>> enum1 == ['T0', 'T1']
False
>>> enum1 == 2
False
Get the concrete value of the enumerated value with that name.
The name of the enumerated value must be a string. If there is no value with that name in the enumeration, an AttributeError is raised.
Examples
Let enum be an enumerated type defined as:
>>> enum = Enum({'T0': 0, 'T1': 2, 'T2': 5})
then:
>>> enum.T1
2
>>> enum.foo
Traceback (most recent call last):
...
AttributeError: no enumerated value with that name: 'foo'
Get the concrete value of the enumerated value with that name.
The name of the enumerated value must be a string. If there is no value with that name in the enumeration, a KeyError is raised.
Examples
Let enum be an enumerated type defined as:
>>> enum = Enum({'T0': 0, 'T1': 2, 'T2': 5})
then:
>>> enum['T1']
2
>>> enum['foo']
Traceback (most recent call last):
...
KeyError: "no enumerated value with that name: 'foo'"
Iterate over the enumerated values.
Enumerated values are returned as (name, value) pairs in no particular order.
Examples
>>> enumvals = {'red': 4, 'green': 2, 'blue': 1}
>>> enum = Enum(enumvals)
>>> enumdict = dict([(name, value) for (name, value) in enum])
>>> enumvals == enumdict
True
Return the number of enumerated values in the enumerated type.
Examples
>>> len(Enum(['e%d' % i for i in range(10)]))
10
Return the canonical string representation of the enumeration. The output of this method can be evaluated to give a new enumeration object that will compare equal to this one.
Examples
>>> repr(Enum({'name': 10}))
"Enum({'name': 10})"
This class represents datasets not supported by PyTables in an HDF5 file.
When reading a generic HDF5 file (i.e. one that has not been created with PyTables, but with some other HDF5 library based tool), chances are that the specific combination of datatypes or dataspaces in some dataset might not be supported by PyTables yet. In such a case, this dataset will be mapped into an UnImplemented instance and the user will still be able to access the complete object tree of the generic HDF5 file. The user will also be able to read and write the attributes of the dataset, access some of its metadata, and perform certain hierarchy manipulation operations like deleting or moving (but not copying) the node. Of course, the user will not be able to read the actual data on it.
This is an elegant way to allow users to work with generic HDF5 files despite the fact that some of its datasets are not supported by PyTables. However, if you are really interested in having full access to an unimplemented dataset, please get in contact with the developer team.
This class does not have any public instance variables or methods, except those inherited from the Leaf class (see The Leaf class).
The endianness of data in memory (‘big’, ‘little’ or ‘irrelevant’).
The length of the first dimension of the data.
The shape of the stored data.
This class represents nodes reported as unknown by the underlying HDF5 library.
This class does not have any public instance variables or methods, except those inherited from the Node class.
In the exceptions module exceptions and warnings that are specific to PyTables are declared.
A low level HDF5 operation failed.
This exception is raised the low level PyTables components used for accessing HDF5 files. It usually signals that something is not going well in the HDF5 library or even at the Input/Output level.
Errors in the HDF5 C library may be accompanied by an extensive HDF5 back trace on standard error (see also tables.silence_hdf5_messages()).
Changed in version 2.4.
Parameters : | message :
h5bt :
|
---|
Convert the HDF5 trace back represented as a list of tuples (see HDF5ExtError.h5backtrace) into a string.
New in version 2.4.
Default policy for HDF5 backtrace handling
This parameter can be set using the PT_DEFAULT_H5_BACKTRACE_POLICY environment variable. Allowed values are “IGNORE” (or “FALSE”), “SAVE” (or “TRUE”) and “VERBOSE” to set the policy to False, True and “VERBOSE” respectively. The special value “DEFAULT” can be used to reset the policy to the default value
New in version 2.4.
HDF5 back trace.
Contains the HDF5 back trace as a (possibly empty) list of tuples. Each tuple has the following format:
(filename, line number, function name, text)
Depending on the value of the h5bt parameter passed to the initializer the h5backtrace attribute can be set to None. This means that the HDF5 back trace has been simply ignored (not retrieved from the HDF5 C library error stack) or that there has been an error (silently ignored) during the HDF5 back trace retrieval.
New in version 2.4.
See also
The operation can not be completed because the node is closed.
For instance, listing the children of a closed group is not allowed.
The operation can not be completed because the hosting file is closed.
For instance, getting an existing node from a closed file is not allowed.
The operation can not be carried out because the mode in which the hosting file is opened is not adequate.
For instance, removing an existing leaf from a read-only file is not allowed.
Invalid hierarchy manipulation operation requested.
This exception is raised when the user requests an operation on the hierarchy which can not be run because of the current layout of the tree. This includes accessing nonexistent nodes, moving or copying or creating over an existing node, non-recursively removing groups with children, and other similarly invalid operations.
A node in a PyTables database cannot be simply overwritten by replacing it. Instead, the old node must be removed explicitely before another one can take its place. This is done to protect interactive users from inadvertedly deleting whole trees of data by a single erroneous command.
An operation was requested on a node that does not exist.
This exception is raised when an operation gets a path name or a (where, name) pair leading to a nonexistent node.
Problems with doing/redoing actions with Undo/Redo feature.
This exception indicates a problem related to the Undo/Redo mechanism, such as trying to undo or redo actions with this mechanism disabled, or going to a nonexistent mark.
Issued when an action not supporting Undo/Redo is run.
This warning is only shown when the Undo/Redo mechanism is enabled.
Issued when a non-pythonic name is given for a node.
This is not an error and may even be very useful in certain contexts, but one should be aware that such nodes cannot be accessed using natural naming (instead, getattr() must be used explicitly).
Warning for operations which may cause a performance drop.
This warning is issued when an operation is made on the database which may cause it to slow down on future operations (i.e. making the node tree grow too much).
Unsupported or unavailable flavor or flavor conversion.
This exception is raised when an unsupported or unavailable flavor is given to a dataset, or when a conversion of data between two given flavors is not supported nor available.
Unsupported or unavailable flavor conversion.
This warning is issued when a conversion of data between two given flavors is not supported nor available, and raising an error would render the data inaccessible (e.g. on a dataset of an unavailable flavor in a read-only file).
See the FlavorError class for more information.
Unavailable filters.
This warning is issued when a valid filter is specified but it is not available in the system. It may mean that an available default filter is to be used instead.
Unsupported index format.
This warning is issued when an index in an unsupported format is found. The index will be marked as invalid and will behave as if doesn’t exist.
Unsupported data type.
This warning is issued when an unsupported HDF5 data type is found (normally in a file created with other tool than PyTables).
Generic warning for experimental features.
This warning is issued when using a functionality that is still experimental and that users have to use with care.