iode.Variables.sample

property Variables.sample: Sample

Current (or new) sample of the IODE Variables database.

If a new sample is given, two cases are possible:

  • the sample is shorter than the current sample: the data beyond the new sample is destroyed,

  • the sample is longer than the current sample: the value NA (not available) is set for the added periods.

Parameters:
value: str or tuple(str, str)

New sample as string ‘start_period:last_period’ or as a tuple ‘start_period’, ‘last_period’.

Warning

Changing the sample on a subset of the Variables workspace is not allowed unless the copy() method has been used (in that case, any change made on the subset will not be reflected in the global Variables workspace).

Examples

>>> from iode import SAMPLE_DATA_DIR
>>> from iode import variables
>>> variables.clear()
>>> variables.sample
None
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading .../fun.var
394 objects loaded
>>> variables.sample
Sample("1960Y1:2015Y1")
>>> variables['ACAF']
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1960Y1:2015Y1
mode: LEVEL

name        1960Y1  1961Y1  ...  2014Y1   2015Y1
ACAF            na      na  ...  -83.34   -96.41
>>> # -- update sample by passing a string
>>> # case 1: new sample is shorter than the current sample
>>> #         the data beyond the new sample is destroyed
>>> variables.sample = '1970Y1:2010Y1'
>>> variables.sample
Sample("1970Y1:2010Y1")
>>> variables['ACAF']
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1970Y1:2010Y1
mode: LEVEL

name        1970Y1  1971Y1  ...  2009Y1   2010Y1
ACAF          1.21    5.20  ...  -37.46   -37.83

>>> # case 2: new sample is longer than the current sample
>>> #         the value NA (not available) is set for the added periods
>>> variables.sample = '1968Y1:2012Y1'
>>> variables.sample
Sample("1968Y1:2012Y1")
>>> variables['ACAF']
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1968Y1:2012Y1
mode: LEVEL

name        1968Y1  1969Y1  1970Y1  ...  2010Y1 2011Y1   2012Y1
ACAF            na      na    1.21  ...  -37.83     na       na
>>> # -- start period is optional -> the start period is kept as it is
>>> variables.sample = ':2010Y1'
>>> variables.sample
Sample("1968Y1:2010Y1")
>>> variables['ACAF']
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1968Y1:2010Y1
mode: LEVEL

name        1968Y1  1969Y1  1970Y1  ...  2009Y1   2010Y1
ACAF            na      na    1.21  ...  -37.46   -37.83

>>> # -- end period is optional -> the end period is kept as it is
>>> variables.sample = '1970Y1:'
>>> variables.sample
Sample("1970Y1:2010Y1")
>>> variables['ACAF']
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1970Y1:2010Y1
mode: LEVEL

name        1970Y1  1971Y1  ...  2009Y1   2010Y1
ACAF          1.21    5.20  ...  -37.46   -37.83
>>> # update sample by passing a start period and 
>>> # an end period separated by a comma
>>> variables.sample = '1968Y1', '2012Y1'
>>> variables.sample
Sample("1968Y1:2012Y1")
>>> variables['ACAF']
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1968Y1:2012Y1
mode: LEVEL

name        1968Y1  1969Y1  1970Y1  ...  2010Y1 2011Y1   2012Y1
ACAF            na      na    1.21  ...  -37.83     na       na