Parentheses · ( )
---
config:
flowchart:
useMaxWidth: false
---
flowchart TB
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Parentheses · ( )<br/>🟢3"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_ds["(DS)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_comp["(comp)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc["(sc)"]:::ok
end
O --- G_ds
O --- G_comp
O --- G_sc
style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
click v_ds href "#form-ds"
click v_comp href "#form-comp"
click v_sc href "#form-sc"
Types
Takes any scalar · Gives any type
Comes from: any operator that returns a value
Goes to: whatever takes its input's type
Forms
(DS) 🟢 · any scalar → any type
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
(DS_1 + DS_2) * DS_2: the sum in the parentheses comes first, then the product withDS_2, on the data points that the operands share.- Manual:
Parentheses, Example 1, output verbatim: “The part of the expression inside the parentheses is evaluated before the part outside of the parentheses.”
- Expected:
Only (10, A) and (11, B) are in both datasets:
Me_1is(5 + 10) * 10 = 150and(4 + 6) * 6 = 60, an Integer, andMe_2is(5.0 + 3.0) * 3.0 = 24.0and(20.3 + 7.0) * 7.0 = 191.1, a Number. Without the parentheses, (10, A) would give 105 and 14.0.
DS_r := (DS_1 + DS_2) * DS_2;
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 5 | 5.0 |
| 10 | B | 2 | 10.5 |
| 11 | A | 3 | 12.2 |
| 11 | B | 4 | 20.3 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 10 | 3.0 |
| 10 | C | 11 | 6.2 |
| 11 | B | 6 | 7.0 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 150 | 24.0 |
| 11 | B | 60 | 191.1 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
(comp) 🟢 · any scalar → any type
Precedence in calc 🟢 pandas ✅ · DuckDB ✅
- Tests:
Parentheses on components inside
calc:(Me_1 + 2) * 3adds before it multiplies.- Manual:
Parentheses: “The operations enclosed in the parentheses are evaluated first”, with
( CMP_1 - CMP_2 )among the valid syntaxes andopof typedataset | component | scalar.- Expected:
Me_2is(1 + 2) * 3 = 9and(4 + 2) * 3 = 18, Integers; without the parentheses the multiplication would come first and give 7 and 10.
DS_r := DS_1[calc Me_2 := (Me_1 + 2) * 3];
| Id_1 | Me_1 |
|---|---|
| 1 | 1 |
| 2 | 4 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 1 | 9 |
| 2 | 4 | 18 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
(sc) 🟢 · any scalar → any type
Addition first 🟢 pandas ✅ · DuckDB ✅
- Tests:
Parentheses on scalars:
(SC_1 + SC_2) * SC_3withSC_1= 2,SC_2= 3 andSC_3= 4 adds before it multiplies.- Manual:
Parentheses: “For example
(2+3)*4returns20, instead2+3*4returns14because the multiplication has higher precedence than the addition.”- Expected:
SC_r = 20, an Integer, as the operands are integers.
SC_r := (SC_1 + SC_2) * SC_3;
| SC_1 | SC_2 | SC_3 |
|---|---|---|
| 2 | 3 | 4 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
Nested parentheses 🟢 pandas ✅ · DuckDB ✅
- Tests:
Nested parentheses,
( SC_1 - SC_2 / (SC_3 + SC_4) ) * SC_5withSC_1= 20,SC_2= 10,SC_3= 2,SC_4= 3 andSC_5= 3: the inner ones are evaluated first.- Manual:
Parentheses: “If more parentheses are nested, the inner parentheses are evaluated first, for example
( 20 - 10 / (2 + 3) ) * 3would give54.”- Expected:
2 + 3 = 5,10 / 5 = 2,20 - 2 = 18and18 * 3 = 54:SC_r = 54, a Number, as a division gives a number (Division page) and so does an operation with a number operand (Subtraction and Multiplication pages).
SC_r := ( SC_1 - SC_2 / (SC_3 + SC_4) ) * SC_5;
| SC_1 | SC_2 | SC_3 | SC_4 | SC_5 |
|---|---|---|---|---|
| 20 | 10 | 2 | 3 | 3 |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗