larray.CheckedParameters

class larray.CheckedParameters(*args, meta=None, **kwargs)[source]

Same as py:class:CheckedSession but declared variables cannot be modified after initialization.

Parameters
*argsstr or dict of {str: object} or iterable of tuples (str, object)

Path to the file containing the session to load or list/tuple/dictionary containing couples (name, object).

**kwargsdict of {str: object}
  • Objects to add written as name=object

  • metalist of pairs or dict or Metadata, optional

    Metadata (title, description, author, creation_date, …) associated with the array. Keys must be strings. Values must be of type string, int, float, date, time or datetime.

See also

CheckedSession

Examples

Content of file ‘parameters.py’

>>> from larray import *
>>> class Parameters(CheckedParameters):
...     # --- declare variables with fixed values ---
...     # The given values can never be changed
...     FIRST_YEAR = 2020
...     LAST_YEAR = 2030
...     AGE = Axis('age=0..10')
...     GENDER = Axis('gender=male,female')
...     TIME = Axis(f'time={FIRST_YEAR}..{LAST_YEAR}')
...     # --- declare variables with defined types ---
...     # Their values must be defined at initialized and will be frozen after.
...     variant_name: str

Content of file ‘model.py’

>>> # instantiation --> create an instance of the ModelVariables class
>>> # all variables declared without value must be set
>>> P = Parameters(variant_name='variant_1')
>>> # once an instance is created, its variables can be accessed but not modified
>>> P.variant_name
'variant_1'
>>> P.variant_name = 'new_variant'      
Traceback (most recent call last):
    ...
TypeError: Cannot change the value of the variable 'variant_name' since 'Parameters'
is immutable and does not support item assignment
__init__(*args, meta=None, **kwargs)[source]

Methods

__init__(*args[, meta])

add(*args, **kwargs)

Deprecated.

apply(func, *args[, kind])

Apply function func on elements of the session and return a new session.

array_equals(**kwargs)

compact([display])

Detect and remove "useless" axes (ie axes for which values are constant over the whole axis) for all array objects in session.

copy()

Return a copy of the session.

dict([exclude])

dump(**kwargs)

dump_csv(**kwargs)

dump_excel(**kwargs)

dump_hdf(**kwargs)

element_equals(other[, rtol, atol, nans_equal])

Test if each element (group, axis and array) of the current session equals the corresponding element of another session.

equals(other[, rtol, atol, nans_equal])

Test if all elements (groups, axes and arrays) of the current session are equal to those of another session.

filter([pattern, kind])

Return a new session with objects which match some criteria.

get(key[, default])

Return the object corresponding to the key.

items()

Return a view of the session's items ((key, value) pairs).

keys()

Return a view on the session's keys.

load(fname[, names, engine, display])

Load objects from a file, or several .csv files.

save(fname[, names, engine, overwrite, display])

Dump objects from the current session to a file, or several .csv files.

summary([template])

Return a summary of the content of the session.

to_csv(fname[, names, display])

Dump Array objects from the current session to CSV files.

to_excel(fname[, names, overwrite, display])

Dump Array objects from the current session to an Excel file.

to_globals([names, depth, warn, inplace])

Create global variables out of objects in the session.

to_hdf(fname[, names, overwrite, display])

Dump objects from the current session to an HDF file.

to_pickle(fname[, names, overwrite, display])

Dump objects from the current session to a file using pickle.

transpose(*args)

Reorder axes of arrays in session, ignoring missing axes for each array.

update([other])

Update the session with the key/value pairs from other or passed keyword arguments, overwriting existing keys.

values()

Return a view on the session's values.

Attributes

memory_used

Return the memory consumed by the session in human readable form.

meta

Return metadata of the session.

names

Return the list of names of the objects in the session.

nbytes

Return the memory in bytes consumed by the session.