MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / Lineage

Class Lineage

functional/lineage.py:5–79  ·  view source on GitHub ↗

Class for tracking the lineage of transformations, and applying them to a given sequence.

Source from the content-addressed store, hash-verified

3
4
5class Lineage(object):
6 """
7 Class for tracking the lineage of transformations, and applying them to a given sequence.
8 """
9
10 def __init__(self, prior_lineage=None, engine=None):
11 """
12 Construct an empty lineage if prior_lineage is None or if its not use it as the list of
13 current transformations
14
15 :param prior_lineage: Lineage object to inherit
16 :return: new Lineage object
17 """
18 self.transformations = (
19 [] if prior_lineage is None else list(prior_lineage.transformations)
20 )
21 self.engine = (
22 (engine or ExecutionEngine())
23 if prior_lineage is None
24 else prior_lineage.engine
25 )
26
27 def __repr__(self):
28 """
29 Returns readable representation of Lineage
30
31 :return: readable Lineage
32 """
33 return "Lineage: " + " -> ".join(
34 ["sequence"] + [transform.name for transform in self.transformations]
35 )
36
37 def __len__(self):
38 """
39 Number of transformations in lineage
40
41 :return: number of transformations
42 """
43 return len(self.transformations)
44
45 def __getitem__(self, item):
46 """
47 Return specific transformation in lineage.
48 :param item: Transformation to retrieve
49 :return: Requested transformation
50 """
51 return self.transformations[item]
52
53 def apply(self, transform):
54 """
55 Add the transformation to the lineage
56 :param transform: Transformation to apply
57 """
58 self.transformations.append(transform)
59
60 def evaluate(self, sequence):
61 """
62 Compute the lineage on the sequence.

Callers 2

__init__Method · 0.90
cacheMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected