larray.CheckedParameters

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

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

Parameters:
*args : str 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).

**kwargs : dict of {str: object}
  • Objects to add written as name=object
  • meta : list 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'      # doctest: +NORMALIZE_WHITESPACE
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]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(*args[, meta]) Initialize self.
add(*args, **kwargs) Adds objects to the current session.
apply(func, *args[, kind]) Apply function func on elements of the session and return a new session.
array_equals(**kwargs)
compact([display]) Detects and removes “useless” axes (ie axes for which values are constant over the whole axis) for all array objects in session
copy() Returns 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]) Returns a new session with objects which match some criteria.
get(key[, default]) Returns the object corresponding to the key.
items() Returns a view of the session’s items ((key, value) pairs).
keys() Returns 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]) Dumps objects from the current session to a file, or several .csv files.
summary([template]) Returns a summary of the content of the session.
to_csv(fname[, names, display]) Dumps Array objects from the current session to CSV files.
to_excel(fname[, names, overwrite, display]) Dumps 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]) Dumps objects from the current session to an HDF file.
to_pickle(fname[, names, overwrite, display]) Dumps 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() Returns a view on the session’s values.

Attributes

meta Returns metadata of the session.
names Returns the list of names of the objects in the session.