-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck.py
90 lines (69 loc) · 2.62 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import typing
import enum
import pandas as pd
import pydantic
from retrack.nodes.base import BaseNode, InputConnectionModel, OutputConnectionModel
###############################################################
# Check Metadata Models
###############################################################
class CheckOperator(str, enum.Enum):
EQUAL = "=="
NOT_EQUAL = "!="
GREATER_THAN = ">"
LESS_THAN = "<"
GREATER_THAN_OR_EQUAL = ">="
LESS_THAN_OR_EQUAL = "<="
def __str__(self):
return self.value
def __repr__(self) -> str:
return self.value
class CheckMetadataModel(pydantic.BaseModel):
operator: typing.Optional[CheckOperator] = CheckOperator.EQUAL
###############################################################
# Check Inputs and Outputs
###############################################################
class CheckInputsModel(pydantic.BaseModel):
input_value_0: InputConnectionModel
input_value_1: InputConnectionModel
class CheckOutputsModel(pydantic.BaseModel):
output_bool: OutputConnectionModel
###############################################################
# Check Node
###############################################################
class Check(BaseNode):
data: CheckMetadataModel
inputs: CheckInputsModel
outputs: CheckOutputsModel
def run(
self,
input_value_0: pd.Series,
input_value_1: pd.Series,
) -> typing.Dict[str, pd.Series]:
if self.data.operator == CheckOperator.EQUAL:
return {
"output_bool": input_value_0.astype(str) == input_value_1.astype(str)
}
elif self.data.operator == CheckOperator.NOT_EQUAL:
return {
"output_bool": input_value_0.astype(str) != input_value_1.astype(str)
}
elif self.data.operator == CheckOperator.GREATER_THAN:
return {
"output_bool": input_value_0.astype(float) > input_value_1.astype(float)
}
elif self.data.operator == CheckOperator.LESS_THAN:
return {
"output_bool": input_value_0.astype(float) < input_value_1.astype(float)
}
elif self.data.operator == CheckOperator.GREATER_THAN_OR_EQUAL:
return {
"output_bool": input_value_0.astype(float)
>= input_value_1.astype(float)
}
elif self.data.operator == CheckOperator.LESS_THAN_OR_EQUAL:
return {
"output_bool": input_value_0.astype(float)
<= input_value_1.astype(float)
}
else:
raise ValueError("Unknown operator")