Flow to stock · flow_to_stock
---
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
fill_time_seriesStock to flow stock_to_flowTime shift timeshiftTime aggregation time_aggActual time current_dateDays between two dates datediffAdd time unit to date dateaddExtract the year getyearExtract the month getmonthExtract the day of the month dayofmonthExtract the day of the year dayofyearYears and days to number of days yeartodayMonths and days to number of days monthtodayAggregate 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
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
period_indicatorFill time series fill_time_seriesStock to flow stock_to_flowTime shift timeshiftTime aggregation time_aggDays between two dates datediffAdd time unit to date dateaddExtract the year getyearExtract the month getmonthExtract the day of the month dayofmonthExtract the day of the year dayofyearHierarchical 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
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:
A2, 7, 4, 13 andB4, -4, -4, 2, Integers as in the input.
DS_r := flow_to_stock ( DS_3 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010 | 2 |
| A | 2011 | 5 |
| A | 2012 | -3 |
| A | 2013 | 9 |
| B | 2010 | 4 |
| B | 2011 | -8 |
| B | 2012 | 0 |
| B | 2013 | 6 |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010 | 2 |
| A | 2011 | 7 |
| A | 2012 | 4 |
| A | 2013 | 13 |
| B | 2010 | 4 |
| B | 2011 | -4 |
| B | 2012 | -4 |
| B | 2013 | 2 |
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 phenomenonA, 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 in2010-Q1, the same periods as2010Q1.
DS_r := flow_to_stock ( DS_4 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010 | 2 |
| A | 2011 | 7 |
| A | 2012 | 4 |
| A | 2013 | 13 |
| A | 2010Q1 | 2 |
| A | 2010Q2 | -3 |
| A | 2010Q3 | 7 |
| A | 2010Q4 | -4 |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010 | 2 |
| A | 2011 | 9 |
| A | 2012 | 13 |
| A | 2013 | 26 |
| A | 2010-Q1 | 2 |
| A | 2010-Q2 | -1 |
| A | 2010-Q3 | 6 |
| A | 2010-Q4 | 2 |
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:
A2, 7, 4, 13 andB4, -4, -4, 2; the fourth date of each series is9999-12-31, as the manual’s input has it.
DS_r := flow_to_stock ( DS_2 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010-12-31 | 2 |
| A | 2011-12-31 | 5 |
| A | 2012-12-31 | -3 |
| A | 9999-12-31 | 9 |
| B | 2010-12-31 | 4 |
| B | 2011-12-31 | -8 |
| B | 2012-12-31 | 0 |
| B | 9999-12-31 | 6 |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010-12-31 | 2 |
| A | 2011-12-31 | 7 |
| A | 2012-12-31 | 4 |
| A | 9999-12-31 | 13 |
| B | 2010-12-31 | 4 |
| B | 2011-12-31 | -4 |
| B | 2012-12-31 | -4 |
| B | 9999-12-31 | 2 |
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:
A2, 7, 4, 13 andB4, -4, -4, 2, an IntegerMe_1.- Erratum:
The manual’s output structure declares
Me_1as String, but the result has “the same Identifier, Measure and Attribute Components as the operand Data Set”, whoseMe_1is Integer, and the values are integers: the expectedMe_1is Integer.- Adaptation:
The page writes its time values in “the time format YYYY-MM/YYYY-MM”, as
2010M1/2010M12, which vtlengine cannot load (DataLoadError0-3-1-6on both engines). EachYYYYM1/YYYYM12of the input and the output is writtenYYYY-01-01/YYYY-12-31, the same interval in theYYYY-MM-DD/YYYY-MM-DDform of the manual’s “Behaviour of Time operators” and ofdocs/data_types.rst; nothing else changes.
DS_r := flow_to_stock ( DS_1 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010-01-01/2010-12-31 | 2 |
| A | 2011-01-01/2011-12-31 | 5 |
| A | 2012-01-01/2012-12-31 | -3 |
| A | 2013-01-01/2013-12-31 | 9 |
| B | 2010-01-01/2010-12-31 | 4 |
| B | 2011-01-01/2011-12-31 | -8 |
| B | 2012-01-01/2012-12-31 | 0 |
| B | 2013-01-01/2013-12-31 | 6 |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010-01-01/2010-12-31 | 2 |
| A | 2011-01-01/2011-12-31 | 7 |
| A | 2012-01-01/2012-12-31 | 4 |
| A | 2013-01-01/2013-12-31 | 13 |
| B | 2010-01-01/2010-12-31 | 4 |
| B | 2011-01-01/2011-12-31 | -4 |
| B | 2012-01-01/2012-12-31 | -4 |
| B | 2013-01-01/2013-12-31 | 2 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗