← stock_to_flow operator page · time/stock_to_flow/date/manual_ex_2

Manual example 2 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

stock_to_flow(DS_2) on annual date series, where "conventionally each period is identified by its last day".

Manual:

Stock to flow, Example 2, output verbatim: "for each time series, calculates the corresponding flow data by subtracting from the measure values of each regular period the corresponding measure values of the previous one."

Expected:

The first value of each series, then the differences: A 2.0, 5.0, -3.0, 9.0 and B 4.0, -8.0, 0.0, 6.0.

script.vtl ⇩

DS_r := stock_to_flow ( DS_2 );

input/DS_2.csv ⇩

Id_1Id_2Me_1
A2010-12-312.0
A2011-12-317.0
A2012-12-314.0
A2013-12-3113.0
B2010-12-314.0
B2011-12-31-4.0
B2012-12-31-4.0
B2013-12-312.0

input/DS_2.json ⇩

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

expected/DS_r.csv ⇩

Id_1Id_2Me_1
A2010-12-312.0
A2011-12-315.0
A2012-12-31-3.0
A2013-12-319.0
B2010-12-314.0
B2011-12-31-8.0
B2012-12-310.0
B2013-12-316.0

expected/DS_r.json ⇩

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