Unpack¶
-
class
dabstract.abstract.abstract.UnpackAbstract(data: dict, keys: List[str])¶ Bases:
dabstract.abstract.abstract.AbstractThe class is an abstract wrapper around a dictionary or DictSeqAbstract to unpack this dictionary in a lazy manner. Unpacking refers to copying the content of the dictionary into a list.
Unpacking is based on the parameter “keys”. For example, consider a Dict or DictSeqAbstract with the following content:
$ data = {'data': [10,5,8], $ 'label': [1,1,2], $ 'other': ['some','other','information']To index this such that it returns a tuple containing the indexed item of keys ‘data’ and ‘label’, one can do:
$ data_up = UnpackAbstract(data,keys=['data','label']) $ print(data_up[0]) [10, 1]
To index through the data one could directly use default indexing, i.e. [idx] or use the .get() method.
The UnpackAbstract contains the following methods:
.get - return entry form UnpackAbstract
The full explanation for each method is provided as a docstring at each method.
- Parameters
- datadict or tvDictSeqAbstract
dictionary or DictSeqAbstract to be unpacked
- keysList[str]
list containing the strings that are used as keys
- Returns
- UnpackAbstract class
-
get(index: int, return_info: bool = False) → List[Any]¶ - Parameters
- indexint
index to retrieve data from
- return_infobool
return tuple (data, info) if True else data (default = False) info contains the information that has been propagated through the chain of operations
- Returns
- ———-
- List of Any