The in-memory representation of a PyTables file.
An instance of this class is returned when a PyTables file is opened with the :func`tables.open_file` function. It offers methods to manipulate (create, rename, delete...) nodes and handle their attributes, as well as methods to traverse the object tree. The user entry point to the object tree attached to the HDF5 file is represented in the root_uep attribute. Other attributes are available.
File objects support an Undo/Redo mechanism which can be enabled with the File.enable_undo() method. Once the Undo/Redo mechanism is enabled, explicit marks (with an optional unique name) can be set on the state of the database using the File.mark() method. There are two implicit marks which are always available: the initial mark (0) and the final mark (-1). Both the identifier of a mark and its name can be used in undo and redo operations.
Hierarchy manipulation operations (node creation, movement and removal) and attribute handling operations (setting and deleting) made after a mark can be undone by using the File.undo() method, which returns the database to the state of a past mark. If undo() is not followed by operations that modify the hierarchy or attributes, the File.redo() method can be used to return the database to the state of a future mark. Else, future states of the database are forgotten.
Note that data handling operations can not be undone nor redone by now. Also, hierarchy manipulation operations on nodes that do not support the Undo/Redo mechanism issue an UndoRedoWarning before changing the database.
The Undo/Redo mechanism is persistent between sessions and can only be disabled by calling the File.disable_undo() method.
File objects can also act as context managers when using the with statement introduced in Python 2.5. When exiting a context, the file is automatically closed.
Parameters : | filename : str
mode : str
title : str
root_uep : str
filters : Filters
|
---|
Notes
In addition, it recognizes the (lowercase) names of parameters present in tables/parameters.py as additional keyword arguments. See PyTables parameter files for a detailed info on the supported parameters.
File attributes
The name of the opened file.
The PyTables version number of this file.
True if the underlying file is open, false otherwise.
The mode in which the file was opened.
The root of the object tree hierarchy (a Group instance).
The UEP (user entry point) group name in the file (see the open_file() function).
Changed in version 3.0: The rootUEP attribute has been renamed into root_uep.
The title of the root group in the file.
Default filter properties for the root group (see The Filters class).
The number of times this file has been opened currently.
Flush all the alive leaves in object tree and close the file.
Copy the contents of this file to dstfilename.
Parameters : | dstfilename : str
overwrite : bool, optional
kwargs :
|
---|
Notes
Additional keyword arguments may be passed to customize the copying process. For instance, title and filters may be changed, user attributes may be or may not be copied, data may be sub-sampled, stats may be collected, etc. Arguments unknown to nodes are simply ignored. Check the documentation for copying operations of nodes to see which options they support.
In addition, it recognizes the names of parameters present in tables/parameters.py as additional keyword arguments. See PyTables parameter files for a detailed info on the supported parameters.
Copying a file usually has the beneficial side effect of creating a more compact and cleaner version of the original file.
Flush all the alive leaves in the object tree.
Return the underlying OS integer file descriptor.
This is needed for lower-level file interfaces, such as the fcntl module.
Enter a context and return the same file.
Exit a context and close the file.
Return a short string representation of the object tree.
Examples
>>> f = tables.open_file('data/test.h5')
>>> print f
data/test.h5 (File) 'Table Benchmark'
Last modif.: 'Mon Sep 20 12:40:47 2004'
Object Tree:
/ (Group) 'Table Benchmark'
/tuple0 (Table(100,)) 'This is the table title'
/group0 (Group) ''
/group0/tuple1 (Table(100,)) 'This is the table title'
/group0/group1 (Group) ''
/group0/group1/tuple2 (Table(100,)) 'This is the table title'
/group0/group1/group2 (Group) ''
Return a detailed string representation of the object tree.
Retrieves an in-memory image of an existing, open HDF5 file.
Note
this method requires HDF5 >= 1.8.9.
New in version 3.0.
Returns the size of an HDF5 file.
The returned size is that of the entire file, as opposed to only the HDF5 portion of the file. I.e., size includes the user block, if any, the HDF5 portion of the file, and any data that may have been appended beyond the data written through the HDF5 Library.
New in version 3.0.
Retrieves the size of a user block.
New in version 3.0.
Copy the children of a group into another group.
Parameters : | srcgroup : str
dstgroup : str
overwrite : bool, optional
recursive : bool, optional
createparents : bool, optional
kwargs : dict
|
---|
Copy the node specified by where and name to newparent/newname.
Parameters : | where : str
newparent : str or Group
newname : str
name : str
overwrite : bool, optional
recursive : bool, optional
createparents : bool, optional
kwargs :
|
---|---|
Returns : | node : Node
|
Create a new array.
Parameters : | where : str or Group
name : str
obj : python object
title : str
byteorder : str
createparents : bool, optional
atom : Atom
shape : tuple of ints
|
---|
See also
Create a new chunked array.
Parameters : | where : str or Group
name : str
atom : Atom
shape : tuple
title : str, optional
filters : Filters, optional
chunkshape : tuple or number or None, optional
byteorder : str, optional
createparents : bool, optional
obj : python object
|
---|
See also
Create a new enlargeable array.
Parameters : | where : str or Group
name : str
atom : Atom
shape : tuple
title : str, optional
expectedrows : int, optional
chunkshape : tuple, numeric, or None, optional
byteorder : str, optional
createparents : bool, optional
obj : python object
|
---|
See also
Create an external link.
Create an external link to a target node with the given name in where location. target can be a node object in another file or a path string in the form ‘file:/path/to/node‘. If createparents is true, the intermediate groups required for reaching where are created (the default is not doing so).
The returned node is an ExternalLink instance.
Create a new group.
Parameters : | where : str or Group
name : str
title : str, optional
filters : Filters
createparents : bool
|
---|
See also
Create a hard link
Create a hard link to a target node with the given name in where location. target can be a node object or a path string. If createparents is true, the intermediate groups required for reaching where are created (the default is not doing so).
The returned node is a regular Group or Leaf instance.
Create a soft link (aka symbolic link) to a target node with the given name in where location. target can be a node object or a path string. If createparents is true, the intermediate groups required for reaching where are created (the default is not doing so).
The returned node is a SoftLink instance. See the SoftLink class (in The SoftLink class) for more information on soft links.
Create a new table with the given name in where location.
Parameters : | where : str or Group
name : str
description : Description
title : str
filters : Filters
expectedrows : int
chunkshape :
byteorder : str
createparents : bool
obj : python object
|
---|
See also
Create a new variable-length array.
Parameters : | where : str or Group
name : str
atom : Atom
title : str, optional
filters : Filters
expectedrows : int, optional
chunkshape : int or tuple of int, optional
byteorder : str, optional
createparents : bool, optional
obj : python object
|
---|
See also
Move the node specified by where and name to newparent/newname.
Parameters : | where, name : path
newparent :
newname :
|
---|
Notes
The other arguments work as in Node._f_move().
Remove the object node name under where location.
Parameters : | where, name :
recursive : bool
|
---|
Change the name of the node specified by where and name to newname.
Parameters : | where, name :
newname : str
overwrite : bool
|
---|
Get the node under where with the given name.
where can be a Node instance (see The Node class) or a path string leading to a node. If no name is specified, that node is returned.
If a name is specified, this must be a string with the name of a node under where. In this case the where argument can only lead to a Group (see The Group class) instance (else a TypeError is raised). The node called name under the group where is returned.
In both cases, if the node to be returned does not exist, a NoSuchNodeError is raised. Please note that hidden nodes are also considered.
If the classname argument is specified, it must be the name of a class derived from Node. If the node is found but it is not an instance of that class, a NoSuchNodeError is also raised.
Is the node under path visible?
If the node does not exist, a NoSuchNodeError is raised.
Iterate over children nodes hanging from where.
Parameters : | where :
classname :
|
---|
Notes
The returned nodes are alphanumerically sorted by their name. This is an iterator version of File.list_nodes().
Return a list with children nodes hanging from where.
This is a list-returning version of File.iter_nodes().
Recursively iterate over groups (not leaves) hanging from where.
The where group itself is listed first (preorder), then each of its child groups (following an alphanumerical order) is also traversed, following the same procedure. If where is not supplied, the root group is used.
The where argument can be a path string or a Group instance (see The Group class).
Recursively iterate over nodes hanging from where.
Parameters : | where : str or Group, optional
classname :
|
---|
Notes
This version iterates over the leaves in the same group in order to avoid having a list referencing to them and thus, preventing the LRU cache to remove them after their use.
Examples
# Recursively print all the nodes hanging from '/detector'.
print "Nodes hanging from group '/detector':"
for node in h5file.walk_nodes('/detector', classname='EArray'):
print node
Is there a node with that path?
Returns True if the file has a node with the given path (a string), False otherwise.
Recursively iterate over the nodes in the tree.
This is equivalent to calling File.walk_nodes() with no arguments.
Examples
# Recursively list all the nodes in the object tree.
h5file = tables.open_file('vlarray1.h5')
print "All nodes in the object tree:"
for node in h5file:
print node
Disable the Undo/Redo mechanism.
Disabling the Undo/Redo mechanism leaves the database in the current state and forgets past and future database states. This makes File.mark(), File.undo(), File.redo() and other methods fail with an UndoRedoError.
Calling this method when the Undo/Redo mechanism is already disabled raises an UndoRedoError.
Enable the Undo/Redo mechanism.
This operation prepares the database for undoing and redoing modifications in the node hierarchy. This allows File.mark(), File.undo(), File.redo() and other methods to be called.
The filters argument, when specified, must be an instance of class Filters (see The Filters class) and is meant for setting the compression values for the action log. The default is having compression enabled, as the gains in terms of space can be considerable. You may want to disable compression if you want maximum speed for Undo/Redo operations.
Calling this method when the Undo/Redo mechanism is already enabled raises an UndoRedoError.
Get the identifier of the current mark.
Returns the identifier of the current mark. This can be used to know the state of a database after an application crash, or to get the identifier of the initial implicit mark after a call to File.enable_undo().
This method can only be called when the Undo/Redo mechanism has been enabled. Otherwise, an UndoRedoError is raised.
Go to a specific mark of the database.
Returns the database to the state associated with the specified mark. Both the identifier of a mark and its name can be used.
This method can only be called when the Undo/Redo mechanism has been enabled. Otherwise, an UndoRedoError is raised.
Is the Undo/Redo mechanism enabled?
Returns True if the Undo/Redo mechanism has been enabled for this file, False otherwise. Please note that this mechanism is persistent, so a newly opened PyTables file may already have Undo/Redo support enabled.
Mark the state of the database.
Creates a mark for the current state of the database. A unique (and immutable) identifier for the mark is returned. An optional name (a string) can be assigned to the mark. Both the identifier of a mark and its name can be used in File.undo() and File.redo() operations. When the name has already been used for another mark, an UndoRedoError is raised.
This method can only be called when the Undo/Redo mechanism has been enabled. Otherwise, an UndoRedoError is raised.
Go to a future state of the database.
Returns the database to the state associated with the specified mark. Both the identifier of a mark and its name can be used. If the mark is omitted, the next created mark is used. If there are no future marks, or the specified mark is not newer than the current one, an UndoRedoError is raised.
This method can only be called when the Undo/Redo mechanism has been enabled. Otherwise, an UndoRedoError is raised.
Go to a past state of the database.
Returns the database to the state associated with the specified mark. Both the identifier of a mark and its name can be used. If the mark is omitted, the last created mark is used. If there are no past marks, or the specified mark is not older than the current one, an UndoRedoError is raised.
This method can only be called when the Undo/Redo mechanism has been enabled. Otherwise, an UndoRedoError is raised.
Copy PyTables attributes from one node to another.
Parameters : | where, name :
dstnode :
|
---|
Delete a PyTables attribute from the given node.
Parameters : | where, name :
attrname :
|
---|
Get a PyTables attribute from the given node.
Parameters : | where, name :
attrname :
|
---|
Set a PyTables attribute for the given node.
Parameters : | where, name :
attrname :
attrvalue :
|
---|
Notes
If the node already has a large number of attributes, a PerformanceWarning is issued.