DataCollection¶
- class gdt.core.collection.DataCollection[source]¶
Bases:
objectA container for a collection of like data objects, such as a collection of
Phaiiobjects. This class exposes the individual objects’ attributes, and it exposes the methods of the object class so that methods can be called on the collection as a whole. For that reason, each object in the DataCollection must be of the same type, otherwise an error is raised. The type of the collection is set by the first object inserted into the collection and the collection type is immutable thereafter.Objects are stored in the collection in the order they are added.
The number of items in the collection can be retrieved by
len()and one can iterate over the items:[data_item for data_item in DataCollection]
In addition to the DataCollection methods, all of the individual object attributes and methods are exposed, and they become methods of the DataCollection. Note that individual object attributes become methods i.e. if you have an item attribute called item.name, then the corresponding DataCollection method would be item.name().
Attributes Summary
The names of the items in the DataCollection
The type of the objects in the DataCollection
Methods Summary
from_list(data_list[, names])Given a list of objects and optionally a list of corresponding names, create a new DataCollection.
get_item(item_name)Retrieve an object from the DataCollection by name
include(data_item[, name])Insert an object into the collection.
remove(item_name)Remove an object from the collection given the name
to_list()Return the objects contained in the DataCollection as a list.
Attributes Documentation
- items¶
The names of the items in the DataCollection
- Type:
(list)
- types¶
The type of the objects in the DataCollection
- Type:
(str)
Methods Documentation
- classmethod from_list(data_list, names=None)[source]¶
Given a list of objects and optionally a list of corresponding names, create a new DataCollection.
- Parameters:
data_list (list of
objects) – The list of objects to be in the collectionnames (list of
str, optional) – The list of corresponding names to the objects. If not set, will try to retrieve a name from object.filename (assuming it’s a data object). If that fails, each item will be named ambiguously ‘item1’, ‘item2’, etc.
- Returns
- get_item(item_name)[source]¶
Retrieve an object from the DataCollection by name
- Parameters:
item_name (str) – The name of the item to retrieve
- Returns:
(
object)
- include(data_item, name=None)[source]¶
Insert an object into the collection. The first item inserted will set the immutable type.
- Parameters:
data_item (
object) – A data object to includename (str, optional) – An optional corresponding name. If not set, will try to retrieve a name from object.filename (assuming it’s a data object). If that fails, each item will be named ambiguously ‘item1’, ‘item2’, etc.