vtlengine 1.0__py3-none-any.whl → 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of vtlengine might be problematic. Click here for more details.
- vtlengine/API/_InternalApi.py +153 -100
- vtlengine/API/__init__.py +109 -67
- vtlengine/AST/ASTConstructor.py +188 -98
- vtlengine/AST/ASTConstructorModules/Expr.py +306 -200
- vtlengine/AST/ASTConstructorModules/ExprComponents.py +172 -102
- vtlengine/AST/ASTConstructorModules/Terminals.py +158 -95
- vtlengine/AST/ASTEncoders.py +1 -1
- vtlengine/AST/ASTTemplate.py +8 -9
- vtlengine/AST/ASTVisitor.py +8 -12
- vtlengine/AST/DAG/__init__.py +43 -35
- vtlengine/AST/DAG/_words.py +4 -4
- vtlengine/AST/Grammar/lexer.py +732 -142
- vtlengine/AST/Grammar/parser.py +2188 -826
- vtlengine/AST/Grammar/tokens.py +128 -128
- vtlengine/AST/VtlVisitor.py +7 -4
- vtlengine/AST/__init__.py +22 -11
- vtlengine/DataTypes/NumericTypesHandling.py +5 -4
- vtlengine/DataTypes/TimeHandling.py +194 -301
- vtlengine/DataTypes/__init__.py +304 -218
- vtlengine/Exceptions/__init__.py +52 -27
- vtlengine/Exceptions/messages.py +134 -62
- vtlengine/Interpreter/__init__.py +781 -487
- vtlengine/Model/__init__.py +165 -121
- vtlengine/Operators/Aggregation.py +156 -95
- vtlengine/Operators/Analytic.py +115 -59
- vtlengine/Operators/Assignment.py +7 -4
- vtlengine/Operators/Boolean.py +27 -32
- vtlengine/Operators/CastOperator.py +177 -131
- vtlengine/Operators/Clause.py +137 -99
- vtlengine/Operators/Comparison.py +148 -117
- vtlengine/Operators/Conditional.py +149 -98
- vtlengine/Operators/General.py +68 -47
- vtlengine/Operators/HROperators.py +91 -72
- vtlengine/Operators/Join.py +217 -118
- vtlengine/Operators/Numeric.py +89 -44
- vtlengine/Operators/RoleSetter.py +16 -15
- vtlengine/Operators/Set.py +61 -36
- vtlengine/Operators/String.py +213 -139
- vtlengine/Operators/Time.py +334 -216
- vtlengine/Operators/Validation.py +117 -76
- vtlengine/Operators/__init__.py +340 -213
- vtlengine/Utils/__init__.py +195 -40
- vtlengine/__init__.py +1 -1
- vtlengine/files/output/__init__.py +15 -6
- vtlengine/files/output/_time_period_representation.py +10 -9
- vtlengine/files/parser/__init__.py +77 -52
- vtlengine/files/parser/_rfc_dialect.py +6 -5
- vtlengine/files/parser/_time_checking.py +46 -37
- vtlengine-1.0.1.dist-info/METADATA +236 -0
- vtlengine-1.0.1.dist-info/RECORD +58 -0
- {vtlengine-1.0.dist-info → vtlengine-1.0.1.dist-info}/WHEEL +1 -1
- vtlengine-1.0.dist-info/METADATA +0 -104
- vtlengine-1.0.dist-info/RECORD +0 -58
- {vtlengine-1.0.dist-info → vtlengine-1.0.1.dist-info}/LICENSE.md +0 -0
|
@@ -17,38 +17,39 @@ def get_measure_from_dataset(dataset: Dataset, code_item: str) -> DataComponent:
|
|
|
17
17
|
data = None
|
|
18
18
|
else:
|
|
19
19
|
data = dataset.data[measure_name]
|
|
20
|
-
return DataComponent(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
return DataComponent(
|
|
21
|
+
name=code_item,
|
|
22
|
+
data=data,
|
|
23
|
+
data_type=dataset.components[measure_name].data_type,
|
|
24
|
+
role=dataset.components[measure_name].role,
|
|
25
|
+
nullable=dataset.components[measure_name].nullable,
|
|
26
|
+
)
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
class HRComparison(Operators.Binary):
|
|
27
30
|
|
|
28
31
|
@classmethod
|
|
29
|
-
def imbalance_func(cls, x, y):
|
|
32
|
+
def imbalance_func(cls, x: Any, y: Any) -> Any:
|
|
30
33
|
if pd.isnull(x) or pd.isnull(y):
|
|
31
34
|
return None
|
|
32
35
|
return x - y
|
|
33
36
|
|
|
34
37
|
@staticmethod
|
|
35
|
-
def hr_func(x, y, hr_mode, func):
|
|
38
|
+
def hr_func(x: Any, y: Any, hr_mode: str, func: Any) -> Any:
|
|
36
39
|
# In comments, it is specified the condition for evaluating the rule,
|
|
37
40
|
# so we delete the cases that does not satisfy the condition
|
|
38
41
|
# (line 6509 of the reference manual)
|
|
39
|
-
if
|
|
40
|
-
|
|
41
|
-
y == "REMOVE_VALUE"):
|
|
42
|
-
if hr_mode == 'partial_null' and pd.isnull(x):
|
|
42
|
+
if hr_mode in ("partial_null", "partial_zero") and not pd.isnull(y) and y == "REMOVE_VALUE":
|
|
43
|
+
if hr_mode == "partial_null" and pd.isnull(x):
|
|
43
44
|
return "REMOVE_VALUE"
|
|
44
|
-
elif hr_mode ==
|
|
45
|
+
elif hr_mode == "partial_zero" and not pd.isnull(x) and x == 0:
|
|
45
46
|
return "REMOVE_VALUE"
|
|
46
47
|
return None
|
|
47
|
-
if hr_mode ==
|
|
48
|
+
if hr_mode == "non_null":
|
|
48
49
|
# If all the involved Data Points are not NULL
|
|
49
50
|
if pd.isnull(x) or pd.isnull(y):
|
|
50
51
|
return "REMOVE_VALUE"
|
|
51
|
-
elif hr_mode ==
|
|
52
|
+
elif hr_mode == "non_zero":
|
|
52
53
|
# If at least one of the involved Data Points is <> zero
|
|
53
54
|
if not (pd.isnull(x) and pd.isnull(y)) and (x == 0 and y == 0):
|
|
54
55
|
return "REMOVE_VALUE"
|
|
@@ -56,64 +57,72 @@ class HRComparison(Operators.Binary):
|
|
|
56
57
|
return func(x, y)
|
|
57
58
|
|
|
58
59
|
@classmethod
|
|
59
|
-
def apply_hr_func(cls, left_series, right_series, hr_mode, func):
|
|
60
|
+
def apply_hr_func(cls, left_series: Any, right_series: Any, hr_mode: str, func: Any) -> Any:
|
|
60
61
|
return left_series.combine(right_series, lambda x, y: cls.hr_func(x, y, hr_mode, func))
|
|
61
62
|
|
|
62
63
|
@classmethod
|
|
63
64
|
def validate(cls, left_operand: Dataset, right_operand: DataComponent, hr_mode: str) -> Dataset:
|
|
64
|
-
result_components = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
65
|
+
result_components = {
|
|
66
|
+
comp_name: copy(comp)
|
|
67
|
+
for comp_name, comp in left_operand.components.items()
|
|
68
|
+
if comp.role == Role.IDENTIFIER
|
|
69
|
+
}
|
|
70
|
+
result_components["bool_var"] = Component(
|
|
71
|
+
name="bool_var", data_type=Boolean, role=Role.MEASURE, nullable=True
|
|
72
|
+
)
|
|
73
|
+
result_components["imbalance"] = Component(
|
|
74
|
+
name="imbalance", data_type=Number, role=Role.MEASURE, nullable=True
|
|
75
|
+
)
|
|
76
|
+
return Dataset(
|
|
77
|
+
name=f"{left_operand.name}{cls.op}{right_operand.name}",
|
|
78
|
+
components=result_components,
|
|
79
|
+
data=None,
|
|
80
|
+
)
|
|
77
81
|
|
|
78
82
|
@classmethod
|
|
79
|
-
def evaluate(
|
|
83
|
+
def evaluate( # type: ignore[override]
|
|
84
|
+
cls, left: Dataset, right: DataComponent, hr_mode: str
|
|
85
|
+
) -> Dataset:
|
|
80
86
|
result = cls.validate(left, right, hr_mode)
|
|
81
|
-
result.data = left.data.copy()
|
|
87
|
+
result.data = left.data.copy() if left.data is not None else pd.DataFrame()
|
|
82
88
|
measure_name = left.get_measures_names()[0]
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
if left.data is not None and right.data is not None:
|
|
90
|
+
result.data["bool_var"] = cls.apply_hr_func(
|
|
91
|
+
left.data[measure_name], right.data, hr_mode, cls.op_func
|
|
92
|
+
)
|
|
93
|
+
result.data["imbalance"] = cls.apply_hr_func(
|
|
94
|
+
left.data[measure_name], right.data, hr_mode, cls.imbalance_func
|
|
95
|
+
)
|
|
87
96
|
# Removing datapoints that should not be returned
|
|
88
97
|
# (we do it below imbalance calculation
|
|
89
98
|
# to avoid errors on different shape)
|
|
90
|
-
result.data = result.data[result.data[
|
|
99
|
+
result.data = result.data[result.data["bool_var"] != "REMOVE_VALUE"]
|
|
91
100
|
result.data.drop(measure_name, axis=1, inplace=True)
|
|
92
101
|
return result
|
|
93
102
|
|
|
94
103
|
|
|
95
104
|
class HREqual(HRComparison):
|
|
96
|
-
op =
|
|
105
|
+
op = "="
|
|
97
106
|
py_op = operator.eq
|
|
98
107
|
|
|
99
108
|
|
|
100
109
|
class HRGreater(HRComparison):
|
|
101
|
-
op =
|
|
110
|
+
op = ">"
|
|
102
111
|
py_op = operator.gt
|
|
103
112
|
|
|
104
113
|
|
|
105
114
|
class HRGreaterEqual(HRComparison):
|
|
106
|
-
op =
|
|
115
|
+
op = ">="
|
|
107
116
|
py_op = operator.ge
|
|
108
117
|
|
|
109
118
|
|
|
110
119
|
class HRLess(HRComparison):
|
|
111
|
-
op =
|
|
120
|
+
op = "<"
|
|
112
121
|
py_op = operator.lt
|
|
113
122
|
|
|
114
123
|
|
|
115
124
|
class HRLessEqual(HRComparison):
|
|
116
|
-
op =
|
|
125
|
+
op = "<="
|
|
117
126
|
py_op = operator.le
|
|
118
127
|
|
|
119
128
|
|
|
@@ -128,38 +137,46 @@ class HRBinNumeric(Operators.Binary):
|
|
|
128
137
|
@classmethod
|
|
129
138
|
def evaluate(cls, left: DataComponent, right: DataComponent) -> DataComponent:
|
|
130
139
|
result_data = cls.apply_operation_two_series(left.data, right.data)
|
|
131
|
-
return DataComponent(
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
return DataComponent(
|
|
141
|
+
name=f"{left.name}{cls.op}{right.name}",
|
|
142
|
+
data=result_data,
|
|
143
|
+
data_type=left.data_type,
|
|
144
|
+
role=left.role,
|
|
145
|
+
nullable=left.nullable,
|
|
146
|
+
)
|
|
134
147
|
|
|
135
148
|
|
|
136
149
|
class HRBinPlus(HRBinNumeric):
|
|
137
|
-
op =
|
|
150
|
+
op = "+"
|
|
138
151
|
py_op = operator.add
|
|
139
152
|
|
|
140
153
|
|
|
141
154
|
class HRBinMinus(HRBinNumeric):
|
|
142
|
-
op =
|
|
155
|
+
op = "-"
|
|
143
156
|
py_op = operator.sub
|
|
144
157
|
|
|
145
158
|
|
|
146
159
|
class HRUnNumeric(Operators.Unary):
|
|
147
160
|
|
|
148
161
|
@classmethod
|
|
149
|
-
def evaluate(cls, operand: DataComponent):
|
|
162
|
+
def evaluate(cls, operand: DataComponent) -> DataComponent: # type: ignore[override]
|
|
150
163
|
result_data = cls.apply_operation_component(operand.data)
|
|
151
|
-
return DataComponent(
|
|
152
|
-
|
|
153
|
-
|
|
164
|
+
return DataComponent(
|
|
165
|
+
name=f"{cls.op}({operand.name})",
|
|
166
|
+
data=result_data,
|
|
167
|
+
data_type=operand.data_type,
|
|
168
|
+
role=operand.role,
|
|
169
|
+
nullable=operand.nullable,
|
|
170
|
+
)
|
|
154
171
|
|
|
155
172
|
|
|
156
173
|
class HRUnPlus(HRUnNumeric):
|
|
157
|
-
op =
|
|
174
|
+
op = "+"
|
|
158
175
|
py_op = operator.pos
|
|
159
176
|
|
|
160
177
|
|
|
161
178
|
class HRUnMinus(HRUnNumeric):
|
|
162
|
-
op =
|
|
179
|
+
op = "-"
|
|
163
180
|
py_op = operator.neg
|
|
164
181
|
|
|
165
182
|
|
|
@@ -167,28 +184,28 @@ class HAAssignment(Operators.Binary):
|
|
|
167
184
|
|
|
168
185
|
@classmethod
|
|
169
186
|
def validate(cls, left: Dataset, right: DataComponent, hr_mode: str) -> Dataset:
|
|
170
|
-
result_components = {comp_name: copy(comp) for comp_name, comp in
|
|
171
|
-
|
|
172
|
-
return Dataset(name=f"{left.name}",
|
|
173
|
-
components=result_components,
|
|
174
|
-
data=None)
|
|
187
|
+
result_components = {comp_name: copy(comp) for comp_name, comp in left.components.items()}
|
|
188
|
+
return Dataset(name=f"{left.name}", components=result_components, data=None)
|
|
175
189
|
|
|
176
190
|
@classmethod
|
|
177
|
-
def evaluate(
|
|
191
|
+
def evaluate( # type: ignore[override]
|
|
192
|
+
cls, left: Dataset, right: DataComponent, hr_mode: str
|
|
193
|
+
) -> Dataset:
|
|
178
194
|
result = cls.validate(left, right, hr_mode)
|
|
179
195
|
measure_name = left.get_measures_names()[0]
|
|
180
|
-
result.data = left.data.copy()
|
|
181
|
-
|
|
196
|
+
result.data = left.data.copy() if left.data is not None else pd.DataFrame()
|
|
197
|
+
if right.data is not None:
|
|
198
|
+
result.data[measure_name] = right.data.map(lambda x: cls.handle_mode(x, hr_mode))
|
|
182
199
|
result.data = result.data[result.data[measure_name] != "REMOVE_VALUE"]
|
|
183
200
|
return result
|
|
184
201
|
|
|
185
202
|
@classmethod
|
|
186
|
-
def handle_mode(cls, x, hr_mode):
|
|
203
|
+
def handle_mode(cls, x: Any, hr_mode: str) -> Any:
|
|
187
204
|
if not pd.isnull(x) and x == "REMOVE_VALUE":
|
|
188
205
|
return "REMOVE_VALUE"
|
|
189
|
-
if hr_mode ==
|
|
206
|
+
if hr_mode == "non_null" and pd.isnull(x):
|
|
190
207
|
return "REMOVE_VALUE"
|
|
191
|
-
elif hr_mode ==
|
|
208
|
+
elif hr_mode == "non_zero" and x == 0:
|
|
192
209
|
return "REMOVE_VALUE"
|
|
193
210
|
return x
|
|
194
211
|
|
|
@@ -204,17 +221,18 @@ class Hierarchy(Operators.Operator):
|
|
|
204
221
|
return df
|
|
205
222
|
|
|
206
223
|
@classmethod
|
|
207
|
-
def validate(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
224
|
+
def validate(
|
|
225
|
+
cls, dataset: Dataset, computed_dict: Dict[str, DataFrame], output: str
|
|
226
|
+
) -> Dataset:
|
|
227
|
+
result_components = {
|
|
228
|
+
comp_name: copy(comp) for comp_name, comp in dataset.components.items()
|
|
229
|
+
}
|
|
230
|
+
return Dataset(name=dataset.name, components=result_components, data=None)
|
|
214
231
|
|
|
215
232
|
@classmethod
|
|
216
|
-
def evaluate(
|
|
217
|
-
|
|
233
|
+
def evaluate(
|
|
234
|
+
cls, dataset: Dataset, computed_dict: Dict[str, DataFrame], output: str
|
|
235
|
+
) -> Dataset:
|
|
218
236
|
result = cls.validate(dataset, computed_dict, output)
|
|
219
237
|
if len(computed_dict) == 0:
|
|
220
238
|
computed_data = pd.DataFrame(columns=dataset.get_components_names())
|
|
@@ -227,7 +245,8 @@ class Hierarchy(Operators.Operator):
|
|
|
227
245
|
# union(setdiff(op, R), R) where R is the computed data.
|
|
228
246
|
# It is the same as union(op, R) and drop duplicates, selecting the last one available
|
|
229
247
|
result.data = pd.concat([dataset.data, computed_data], axis=0, ignore_index=True)
|
|
230
|
-
result.data.drop_duplicates(
|
|
231
|
-
|
|
248
|
+
result.data.drop_duplicates(
|
|
249
|
+
subset=dataset.get_identifiers_names(), keep="last", inplace=True
|
|
250
|
+
)
|
|
232
251
|
result.data.reset_index(drop=True, inplace=True)
|
|
233
252
|
return result
|