Symmetric difference · symdiff

🟢 1 of 1 form all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc2 (90ee9376) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
        ---
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 in DS_1 and one only in DS_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.

script.vtl
DS_r := symdiff ( DS_1, DS_2 );
Input DS_1
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal1
2012GTotalTotal2
2012FTotalTotal3
2012MTotalTotal4
2012ITotalTotal5
2012STotalTotal6
Input DS_2
Id_1Id_2Id_3Id_4Me_1
2011BTotalTotal1
2012GTotalTotal2
2012FTotalTotal3
2012MTotalTotal4
2012ITotalTotal5
2012STotalTotal6
Expected DS_r
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal1
2011BTotalTotal1

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 for DS_1 and 1 for DS_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_1 and 41 from DS_2. Ids 2 and 3 are in both operands, so they are dropped from both sides although their measures differ.

script.vtl
DS_r := symdiff(DS_1, DS_2);
Input DS_1
Id_1Me_1
110
220
330
Input DS_2
Id_1Me_1
221
331
441
Expected DS_r
Id_1Me_1
110
441

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 ↗