Symmetric difference · symdiff
---
config:
flowchart:
useMaxWidth: false
---
flowchart LR
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["Symmetric difference · symdiff<br/>🟢1"]:::ok
v_two["symdiff(DS, DS)"]:::ok
v_two --- O
click v_two href "#form-two"
Types
Takes any scalar · Gives any type
Comes from: any operator that returns a value
Goes to: whatever takes its input's type
Forms
symdiff(DS, DS) 🟢 · any scalar → any type
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
symdiff ( DS_1, DS_2 ): five data points are in both operands, one is only inDS_1and one only inDS_2.- Manual:
Symmetric difference, Example 1, output verbatim: the operator returns a Data Set “containing the Data Points that appear in the first Data Set but not in the second and the Data Points that appear in the second Data Set but not in the first one”.
- Expected:
the page’s two data points, one from each operand: (2012, B, Total, Total) and (2011, B, Total, Total), both with the measure 1.
DS_r := symdiff ( DS_1, DS_2 );
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 1 |
| 2012 | G | Total | Total | 2 |
| 2012 | F | Total | Total | 3 |
| 2012 | M | Total | Total | 4 |
| 2012 | I | Total | Total | 5 |
| 2012 | S | Total | Total | 6 |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2011 | B | Total | Total | 1 |
| 2012 | G | Total | Total | 2 |
| 2012 | F | Total | Total | 3 |
| 2012 | M | Total | Total | 4 |
| 2012 | I | Total | Total | 5 |
| 2012 | S | Total | Total | 6 |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 1 |
| 2011 | B | Total | Total | 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 ↗
Matched by identifiers not measures 🟢 pandas ✅ · DuckDB ✅
- Tests:
symdiff(DS_1, DS_2)where ids 2 and 3 are in both operands with different measures (in the page’s example a shared data point has the same measure in both), to show whether data points are matched by identifiers alone. The measure is 10 *Id_1+ k, with k 0 forDS_1and 1 forDS_2, so its last digit names the operand.- Manual:
Symmetric difference: “Data Points are compared to one another by Identifier Components”; the result has “all the Data Points dp1 contained in ds1 for which there is no Data Point dp2 in ds2 with the same values for homonym Identifier components”, and the same for
ds2.- Expected:
ids 1 and 4: 10 from
DS_1and 41 fromDS_2. Ids 2 and 3 are in both operands, so they are dropped from both sides although their measures differ.
DS_r := symdiff(DS_1, DS_2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| Id_1 | Me_1 |
|---|---|
| 2 | 21 |
| 3 | 31 |
| 4 | 41 |
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 4 | 41 |
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 ↗