← subtraction operator page · numeric/subtraction/ds_ds/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

each measure of DS_2 subtracted from the same measure of DS_1, on the data points that the two datasets share.

Manual:

Subtraction, Example 1, output verbatim: "The operator subtraction returns the difference of two numbers."

Expected:

only (10, A) and (11, B) are in both datasets: 5 - 10 = -5 and 5.0 - 3.0 = 2.0; 4 - 6 = -2 and 20.3 - 7.0 = 13.3.

script.vtl ⇩

DS_r := DS_1 - DS_2;

input/DS_1.csv ⇩

Id_1Id_2Me_1Me_2
10A55.0
10B210.5
11A312.2
11B420.3

input/DS_1.json ⇩

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

input/DS_2.csv ⇩

Id_1Id_2Me_1Me_2
10A103.0
10C116.2
11B67.0

input/DS_2.json ⇩

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

expected/DS_r.csv ⇩

Id_1Id_2Me_1Me_2
10A-52.0
11B-213.3

expected/DS_r.json ⇩

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