← timeshift operator page · time/timeshift/time_period/manual_ex_4

Manual example 4 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

timeshift(DS_4, -1) on an annual and a quarterly series of the same phenomenon A: one period of each series into the past.

Manual:

Time shift, Example 4, output verbatim: the operator "shifts the reference time Identifier of a number of periods (of the time series) equal to the shiftNumber parameter. If shiftNumber is negative, the shift is in the past".

Expected:

The years move back one year, 2010 to 2013 becoming 2009 to 2012, and the quarters one quarter, 2010Q1 to 2010Q4 becoming 2009Q4 to 2010Q3.

script.vtl ⇩

DS_r := timeshift( DS_4 , -1 );

input/DS_4.csv ⇩

Id_1Id_2Me_1
A2010hello world
A2011
A2012say hello
A2013he
A2010Q1hi, hello!
A2010Q2hi
A2010Q3
A2010Q4hello!

input/DS_4.json ⇩

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

expected/DS_r.csv ⇩

Id_1Id_2Me_1
A2009hello world
A2010
A2011say hello
A2012he
A2009Q4hi, hello!
A2010Q1hi
A2010Q2
A2010Q3hello!

expected/DS_r.json ⇩

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