← setdiff operator page · set/setdiff/two/matched_by_identifiers_not_measures

Matched by identifiers not measures 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

setdiff(DS_1, DS_2) where ids 2 and 3 are in both operands with different measures (in the page's examples 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:

Set difference: "the resulting Dataset contains all the data points Data Point dp1 of the operand ds1, such that there is no Data Point dp2 of ds2 having the same values for homonym Identifier Components": the condition is on the identifiers alone.

Expected:

only id 1, with the measure 10 of DS_1. Ids 2 and 3 have a data point in DS_2 with the same identifiers, whatever its measure, and id 4 is only in DS_2, the subtrahend, which adds nothing.

script.vtl ⇩

DS_r := setdiff(DS_1, DS_2);

input/DS_1.csv ⇩

Id_1Me_1
110
220
330

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

input/DS_2.csv ⇩

Id_1Me_1
221
331
441

input/DS_2.json ⇩

{
  "datasets": [
    {
      "name": "DS_2",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_1
110

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Me_1", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}