PyTables User's Guide: Hierarchical datasets in Python - Release 1.3.3
Prev | Chapter 4. Library Reference | Next

# 4.3. The Node class

This is the base class for all nodes in a PyTables hierarchy. It is an abstract class, i.e. it may not be directly instantiated; however, every node in the hierarchy is an instance of this class.

A PyTables node is always hosted in a PyTables file, under a parent group, at a certain depth in the node hierarchy. A node knows its own name in the parent group and its own path name in the file. When using a translation map (see 4.2), its HDF5 name might differ from its PyTables name.

All the previous information is location-dependent, i.e. it may change when moving or renaming a node in the hierarchy. A node also has location-independent information, such as its HDF5 object identifier and its attribute set.

This class gathers the operations and attributes (both location-dependent and independent) which are common to all PyTables nodes, whatever their type is. Nonetheless, due to natural naming restrictions, the names of all of these members start with a reserved prefix (see 4.4).

Sub-classes with no children (i.e. leaf nodes) may define new methods, attributes and properties to avoid natural naming restrictions. For instance, `_v_attrs` may be shortened to `attrs` and `_f_rename` to `rename`. However, the original methods and attributes should still be available.

## 4.3.1. Node instance variables

### 4.3.1.1. Location dependent

_v_file

  The hosting `File` instance (see 4.2).

_v_parent

  The parent `Group` instance (see 4.4).

_v_depth

  The depth of this node in the tree (an non-negative integer value).

_v_name

  The name of this node in its parent group (a string).

_v_hdf5name

  The name of this node in the hosting HDF5 file (a string).

_v_pathname

  The path of this node in the tree (a string).

_v_rootgroup

  The root group instance. This is deprecated; please use `node._v_file.root`.

### 4.3.1.2. Location independent

_v_objectID

  The identifier of this node in the hosting HDF5 file.

_v_attrs

  The associated `AttributeSet` instance (see 4.15).

### 4.3.1.3. Attribute shorthands

_v_title

  A description of this node. A shorthand for `TITLE` attribute.

## 4.3.2. Node methods

### 4.3.2.1. Hierarchy manipulation

_f_close()

  Close this node in the tree.

  This releases all resources held by the node, so it should not be used again. On nodes with data, it may be flushed to disk.

  The closing operation is not recursive, i.e. closing a group does not close its children.

_f_isOpen()

  Is this node open?

_f_remove(recursive=False)

  Remove this node from the hierarchy.

  If the node has children, recursive removal must be stated by giving `recursive` a true value; otherwise, a `NodeError` will be raised.

_f_rename(newname)

  Rename this node in place.

  Changes the name of a node to newname (a string).

_f_move(newparent=None, newname=None, overwrite=False)

  Move or rename this node.

  Moves a node into a new parent group, or changes the name of the node. `newparent` can be a `Group` object or a pathname in string form. If it is not specified or `None`, the current parent group is chosen as the new parent. `newname` must be a string with a new name. If it is not specified or `None`, the current name is chosen as the new name.

  Moving a node across databases is not allowed, nor it is moving a node into itself. These result in a `NodeError`. However, moving a node over itself is allowed and simply does nothing. Moving over another existing node is similarly not allowed, unless the optional `overwrite` argument is true, in which case that node is recursively removed before moving.

  Usually, only the first argument will be used, effectively moving the node to a new location without changing its name. Using only the second argument is equivalent to renaming the node in place.

_f_copy(newparent=None, newname=None, overwrite=False, recursive=False, **kwargs)

  Copy this node and return the new node.

  Creates and returns a copy of the node, maybe in a different place in the hierarchy. `newparent` can be a `Group` object or a pathname in string form. If it is not specified or `None`, the current parent group is chosen as the new parent. `newname` must be a string with a new name. If it is not specified or `None`, the current name is chosen as the new name. If `recursive` copy is stated, all descendants are copied as well.

  Copying a node across databases is supported but can not be undone. Copying a node over itself is not allowed, nor it is recursively copying a node into itself. These result in a `NodeError`. Copying over another existing node is similarly not allowed, unless the optional `overwrite` argument is true, in which case that node is recursively removed before copying.

  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. See the documentation for the particular node type.

  Using only the first argument is equivalent to copying the node to a new location without changing its name. Using only the second argument is equivalent to making a copy of the node in the same group.

_f_isVisible()

  Is this node visible?

### 4.3.2.2. Attribute handling

_f_getAttr(name)

  Get a PyTables attribute from this node.

  If the named attribute does not exist, an `AttributeError` is raised.

_f_setAttr(name, value)

  Set a PyTables attribute for this node.

  If the node already has a large number of attributes, a `PerformanceWarning` is issued.

_f_delAttr(name)

  Delete a PyTables attribute from this node.

  If the named attribute does not exist, an `AttributeError` is raised.

Prev | Home | Next
The File class | Up | The Group class