Flow to stock · flow_to_stock

🟢 3 of 3 forms 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["Flow to stock · flow_to_stock<br/>🟢3"]:::ok
    v_time_period["flow_to_stock(DS) on time_period"]:::ok
    v_date["flow_to_stock(DS) on date"]:::ok
    v_time["flow_to_stock(DS) on time"]:::ok
    v_time_period --- O
    v_date --- O
    O --- v_time
    click v_time_period href "#form-time-period"
    click v_date href "#form-date"
    click v_time href "#form-time"
    

Types

Takes number, time, date, time_period · Gives number, time, date, time_period

Comes from · number, time, date, time_period — 49 operators in 6 blocks 🟢49
General purpose operators (2) 🟢2
String operators (3) 🟢3
Numeric operators (18) 🟢18
Time operators (13) 🟢13
Aggregate and Analytic operators (10) 🟢10
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 34 operators in 7 blocks 🟢34
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Clause operators (9) 🟢9
Goes to · number, time, date, time_period — 43 operators in 7 blocks 🟢43
General purpose operators (1) 🟢1
Numeric operators (18) 🟢18
Time operators (11) 🟢11
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Data validation operators (2) 🟢2
Definitions (VTL-DL) (2) 🟢2
Goes to · operators that take any scalar — 48 operators in 8 blocks 🟢48
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Clause operators (9) 🟢9

Forms

flow_to_stock(DS) on time_period 🟢 · time_period, number → time_period, number

Manual example 3 🟢 pandas ✅ · DuckDB ✅
Tests:

flow_to_stock(DS_3) on annual time_period series.

Manual:

Flow to stock, Example 3, output verbatim: “the operator perform the cumulative sum from the first Data Point of each time series to each other following Data Point of the same time series.”

Expected:

The running sums of each series: A 2, 7, 4, 13 and B 4, -4, -4, 2, Integers as in the input.

script.vtl
DS_r := flow_to_stock ( DS_3 );
Input DS_3
Id_1Id_2Me_1
A20102
A20115
A2012-3
A20139
B20104
B2011-8
B20120
B20136
Expected DS_r
Id_1Id_2Me_1
A20102
A20117
A20124
A201313
B20104
B2011-4
B2012-4
B20132

Files: script.vtl · input/DS_3.csv · input/DS_3.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Manual example 4 🟢 pandas ✅ · DuckDB ✅
Tests:

flow_to_stock(DS_4) on an annual and a quarterly series of the same phenomenon A, each summed on its own.

Manual:

Flow to stock, Example 4, output verbatim: “the operator perform the cumulative sum from the first Data Point of each time series to each other following Data Point of the same time series.”

Expected:

The years give 2, 9, 13, 26 and the quarters of 2010 give 2, -1, 6, 2. The manual writes the quarters with a -, as in 2010-Q1, the same periods as 2010Q1.

script.vtl
DS_r := flow_to_stock ( DS_4 );
Input DS_4
Id_1Id_2Me_1
A20102
A20117
A20124
A201313
A2010Q12
A2010Q2-3
A2010Q37
A2010Q4-4
Expected DS_r
Id_1Id_2Me_1
A20102
A20119
A201213
A201326
A2010-Q12
A2010-Q2-1
A2010-Q36
A2010-Q42

Files: script.vtl · input/DS_4.csv · input/DS_4.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

flow_to_stock(DS) on date 🟢 · date, number → date, number

Manual example 2 🟢 pandas ✅ · DuckDB ✅
Tests:

flow_to_stock(DS_2) on date series, where “conventionally each period is identified by its last day”.

Manual:

Flow to stock, Example 2, output verbatim: “the operator perform the cumulative sum from the first Data Point of each time series to each other following Data Point of the same time series.”

Expected:

A 2, 7, 4, 13 and B 4, -4, -4, 2; the fourth date of each series is 9999-12-31, as the manual’s input has it.

script.vtl
DS_r := flow_to_stock ( DS_2 );
Input DS_2
Id_1Id_2Me_1
A2010-12-312
A2011-12-315
A2012-12-31-3
A9999-12-319
B2010-12-314
B2011-12-31-8
B2012-12-310
B9999-12-316
Expected DS_r
Id_1Id_2Me_1
A2010-12-312
A2011-12-317
A2012-12-314
A9999-12-3113
B2010-12-314
B2011-12-31-4
B2012-12-31-4
B9999-12-312

Files: script.vtl · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

flow_to_stock(DS) on time 🟢 · time, number → time, number

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

flow_to_stock(DS_1) on annual series whose reference time identifier is a time.

Manual:

Flow to stock, Example 1: “the operator perform the cumulative sum from the first Data Point of each time series to each other following Data Point of the same time series.”

Expected:

The manual’s values: A 2, 7, 4, 13 and B 4, -4, -4, 2, an Integer Me_1.

Erratum:

The manual’s output structure declares Me_1 as String, but the result has “the same Identifier, Measure and Attribute Components as the operand Data Set”, whose Me_1 is Integer, and the values are integers: the expected Me_1 is Integer.

Adaptation:

The page writes its time values in “the time format YYYY-MM/YYYY-MM”, as 2010M1/2010M12, which vtlengine cannot load (DataLoadError 0-3-1-6 on both engines). Each YYYYM1/YYYYM12 of the input and the output is written YYYY-01-01/YYYY-12-31, the same interval in the YYYY-MM-DD/YYYY-MM-DD form of the manual’s “Behaviour of Time operators” and of docs/data_types.rst; nothing else changes.

script.vtl
DS_r := flow_to_stock ( DS_1 );
Input DS_1
Id_1Id_2Me_1
A2010-01-01/2010-12-312
A2011-01-01/2011-12-315
A2012-01-01/2012-12-31-3
A2013-01-01/2013-12-319
B2010-01-01/2010-12-314
B2011-01-01/2011-12-31-8
B2012-01-01/2012-12-310
B2013-01-01/2013-12-316
Expected DS_r
Id_1Id_2Me_1
A2010-01-01/2010-12-312
A2011-01-01/2011-12-317
A2012-01-01/2012-12-314
A2013-01-01/2013-12-3113
B2010-01-01/2010-12-314
B2011-01-01/2011-12-31-4
B2012-01-01/2012-12-31-4
B2013-01-01/2013-12-312

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗