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
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]
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods
__init__(*args[, meta])Create a new model by parsing and validating input data from keyword arguments.
add(*args, **kwargs)Deprecated.
align(*other[, join, fill_value])Align the current session with (an)other session(s)
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.
construct([_fields_set])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.
from_orm(obj)get(key[, default])Return the object corresponding to the key.
items()Return a view of the session's items ((key, value) pairs).
json(*[, include, exclude, by_alias, ...])keys()Return a view on the session's keys.
load(fname[, names, engine, display])Load objects from a file, or several .csv files.
model_construct([_fields_set])Creates a new instance of the Model class with validated data.
model_copy(*[, update, deep])!!! abstract "Usage Documentation"
model_dump(*[, mode, include, exclude, ...])!!! abstract "Usage Documentation"
model_dump_json(*[, indent, ensure_ascii, ...])!!! abstract "Usage Documentation"
model_json_schema([by_alias, ref_template, ...])Generates a JSON schema for a model class.
model_parametrized_name(params)Compute the class name for parametrizations of generic classes.
model_post_init(context, /)Override this method to perform additional initialization after __init__ and model_construct.
model_rebuild(*[, force, raise_errors, ...])Try to rebuild the pydantic-core schema for the model.
model_validate(obj, *[, strict, extra, ...])Validate a pydantic model instance.
model_validate_json(json_data, *[, strict, ...])!!! abstract "Usage Documentation"
model_validate_strings(obj, *[, strict, ...])Validate the given object with string data against the Pydantic model.
parse_file(path, *[, content_type, ...])parse_obj(obj)parse_raw(b, *[, content_type, encoding, ...])save(fname[, names, engine, overwrite, display])Dump objects from the current session to a file, or several .csv files.
schema([by_alias, ref_template])schema_json(*[, by_alias, ref_template])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.
update_forward_refs(**localns)validate(value)values()Return a view on the session's values.
Attributes
memory_usedReturn the memory consumed by the session in human readable form.
metaReturn metadata of the session.
model_computed_fieldsmodel_configConfiguration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
model_extraGet extra fields set during validation.
model_fieldsmodel_fields_setReturns the set of fields that have been explicitly set on this model instance.
namesReturn the list of names of the objects in the session.
nbytesReturn the memory in bytes consumed by the session.