Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated if condition merging process to work with new Parentheses AST… #81

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/vtlengine/Interpreter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,8 +1580,20 @@ def generate_then_else_datasets(self, condition: Union[Dataset, DataComponent])
)
}
)

if self.condition_stack and len(self.condition_stack) > 0:
last_condition_dataset = (
self.then_condition_dataset[-1]
if self.condition_stack[-1] == THEN_ELSE["then"]
else (self.else_condition_dataset[-1])
)
measure_name = last_condition_dataset.get_measures_names()[0]
then_data = then_data[then_data[name].isin(last_condition_dataset.data[measure_name])]
else_data = else_data[else_data[name].isin(last_condition_dataset.data[measure_name])]
then_dataset = Dataset(name=name, components=components, data=then_data)
else_dataset = Dataset(name=name, components=components, data=else_data)


self.then_condition_dataset.append(then_dataset)
self.else_condition_dataset.append(else_dataset)

Expand All @@ -1592,11 +1604,13 @@ def merge_then_else_datasets(self, left_operand: Any, right_operand: Any) -> Any
or self.condition_stack is None
):
return left_operand, right_operand

merge_dataset = (
self.then_condition_dataset.pop()
if self.condition_stack.pop() == THEN_ELSE["then"]
else (self.else_condition_dataset.pop())
)

merge_index = merge_dataset.data[merge_dataset.get_measures_names()[0]].to_list()
ids = merge_dataset.get_identifiers_names()
if isinstance(left_operand, (Dataset, DataComponent)):
Expand Down
14 changes: 13 additions & 1 deletion tests/Bugs/data/vtl/GL_195_1.vtl
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
B03.ANAMART_INSTRMNT_SHR_ONA_CRDTR := B03.INSTRMNT_FCT_TRNSFRRD_AMNT [ calc SHR_ONA_CRDTR := if OTSTNDNG_NMNL_AMNT = 0 then 1 / NMBR_CRDTR else ( if OBSRVD_AGNT_CD = CRDTR_ID then ( OTSTNDNG_NMNL_AMNT - TRNSFRRD_AMNT ) / OTSTNDNG_NMNL_AMNT else ( if OTSTNDNG_NMNL_AMNT * NMBR_CRDTRS_NT_OA = 0.0 then 1 else TRNSFRRD_AMNT / ( OTSTNDNG_NMNL_AMNT * NMBR_CRDTRS_NT_OA ) ) ) ] [ keep SHR_ONA_CRDTR ] ;
B03.ANAMART_INSTRMNT_SHR_ONA_CRDTR := B03.INSTRMNT_FCT_TRNSFRRD_AMNT
[ calc SHR_ONA_CRDTR := if OTSTNDNG_NMNL_AMNT = 0
then 1 / NMBR_CRDTR
else (
if OBSRVD_AGNT_CD = CRDTR_ID
then ( OTSTNDNG_NMNL_AMNT - TRNSFRRD_AMNT ) / OTSTNDNG_NMNL_AMNT
else (
if OTSTNDNG_NMNL_AMNT * NMBR_CRDTRS_NT_OA = 0.0 then 1
else TRNSFRRD_AMNT / ( OTSTNDNG_NMNL_AMNT * NMBR_CRDTRS_NT_OA )
)
)
]
[ keep SHR_ONA_CRDTR ] ;