ParameterCollection#

ParameterCollection with own methods only#

class pydidas.core.ParameterCollection(*args: tuple)#

Bases: dict

Ordered collection of parameters, implemented as subclass of dict.

The ParameterCollection is a dictionary for Parameter instances with additional convenience routines to easily get and set Parameter values. Items can be added at instantiation either as single Parameters, ParameterCollections or as keyword arguments. Keywords will be converted to keys for the associated Parameters.

Parameters:
  • *args (Union[Parameter, ParameterCollection]) – Any number of Parameter or ParameterCollection instances

  • **kwargs (dict) – Any number of Parameters

add_param(param: Parameter)#

Add a parameter to the ParameterCollection.

Parameters:

param (Parameter) – An instance of a Parameter object.

Raises:
  • TypeError – If the passed param argument is not a Parameter instance.

  • KeyError – If an entry with param.refkey already exists.

add_params(*args: tuple[Parameter, Self, dict])#

Add parameters to the ParameterCollection.

This method adds Parameters to the ParameterCollection. Parameters can be either supplies individually as arguments or as ParameterCollections or dictionaries.

Parameters:

*args (tuple[Parameter, dict, ParameterCollection]) – Any dict, Parameter or ParameterCollection

copy() Self#

Get a copy of the ParameterCollection.

This method will return a copy of the ParameterCollection with a copy of each Parameter object.

Returns:

The copy of ParameterCollection with no shared objects.

Return type:

ParameterCollection

deepcopy() Self#

Get a copy of the ParameterCollection.

This method will return a copy of the ParameterCollection with a copy of each Parameter object.

Returns:

The copy of ParameterCollection with no shared objects.

Return type:

ParameterCollection

delete_param(key: str)#

Remove a Parameter from the ParameterCollection.

This method is a wrapper for the intrinsic dict.__delitem__ method.

Parameters:

key (str) – The key of the dictionary entry to be removed.

get_param(param_key: str) Parameter#

Get a Parameter from the ParameterCollection.

Parameters:

param_key (str) – The Parameter key.

Returns:

The Parameter instance.

Return type:

Parameter

get_params(*keys: tuple) List[Parameter]#

Get multiple keys from an iterable.

Parameters:

keys (tuple) – The reference keys for all Parameters to be returned.

Returns:

A list of the Parameters.

Return type:

list

get_value(param_key: str) object#

Get the value of a stored parameter.

This method will verify that the entry exists and returns its value in its native type.

Parameters:

param_key (str) – The reference key to the parameter in the dictionary.

Returns:

The value of the Parameter object in its native data type.

Return type:

object

set_value(param_key: str, value: object)#

Update the value of a stored parameter.

This method will verify that the entry exists and update the stored value.

Parameters:
  • param_key (str) – The reference key to the parameter in the dictionary.

  • value (object) – The new value for the Parameter. Note that type-checking is performed in the Parameter value setter.

Raises:

KeyError – If the key “param_key” is not registered.

values_equal(*args: tuple) bool#

Compare all Parameters references by their keys in args and check if they have the same value.

Parameters:

*args (tuple) – Any number of Parameter keys.

Raises:

KeyError – If any of the Parameter reference keys have not been registered with the ParameterCollection.

Returns:

Flag whether all Parameters have identical values or not.

Return type:

bool

ParameterCollection with inherited methods too#

class pydidas.core.ParameterCollection(*args: tuple)

Bases: dict

Ordered collection of parameters, implemented as subclass of dict.

The ParameterCollection is a dictionary for Parameter instances with additional convenience routines to easily get and set Parameter values. Items can be added at instantiation either as single Parameters, ParameterCollections or as keyword arguments. Keywords will be converted to keys for the associated Parameters.

Parameters:
  • *args (Union[Parameter, ParameterCollection]) – Any number of Parameter or ParameterCollection instances

  • **kwargs (dict) – Any number of Parameters

add_param(param: Parameter)

Add a parameter to the ParameterCollection.

Parameters:

param (Parameter) – An instance of a Parameter object.

Raises:
  • TypeError – If the passed param argument is not a Parameter instance.

  • KeyError – If an entry with param.refkey already exists.

add_params(*args: tuple[Parameter, Self, dict])

Add parameters to the ParameterCollection.

This method adds Parameters to the ParameterCollection. Parameters can be either supplies individually as arguments or as ParameterCollections or dictionaries.

Parameters:

*args (tuple[Parameter, dict, ParameterCollection]) – Any dict, Parameter or ParameterCollection

clear() None.  Remove all items from D.
copy() Self

Get a copy of the ParameterCollection.

This method will return a copy of the ParameterCollection with a copy of each Parameter object.

Returns:

The copy of ParameterCollection with no shared objects.

Return type:

ParameterCollection

deepcopy() Self

Get a copy of the ParameterCollection.

This method will return a copy of the ParameterCollection with a copy of each Parameter object.

Returns:

The copy of ParameterCollection with no shared objects.

Return type:

ParameterCollection

delete_param(key: str)

Remove a Parameter from the ParameterCollection.

This method is a wrapper for the intrinsic dict.__delitem__ method.

Parameters:

key (str) – The key of the dictionary entry to be removed.

fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

get_param(param_key: str) Parameter

Get a Parameter from the ParameterCollection.

Parameters:

param_key (str) – The Parameter key.

Returns:

The Parameter instance.

Return type:

Parameter

get_params(*keys: tuple) List[Parameter]

Get multiple keys from an iterable.

Parameters:

keys (tuple) – The reference keys for all Parameters to be returned.

Returns:

A list of the Parameters.

Return type:

list

get_value(param_key: str) object

Get the value of a stored parameter.

This method will verify that the entry exists and returns its value in its native type.

Parameters:

param_key (str) – The reference key to the parameter in the dictionary.

Returns:

The value of the Parameter object in its native data type.

Return type:

object

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

set_value(param_key: str, value: object)

Update the value of a stored parameter.

This method will verify that the entry exists and update the stored value.

Parameters:
  • param_key (str) – The reference key to the parameter in the dictionary.

  • value (object) – The new value for the Parameter. Note that type-checking is performed in the Parameter value setter.

Raises:

KeyError – If the key “param_key” is not registered.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
values_equal(*args: tuple) bool

Compare all Parameters references by their keys in args and check if they have the same value.

Parameters:

*args (tuple) – Any number of Parameter keys.

Raises:

KeyError – If any of the Parameter reference keys have not been registered with the ParameterCollection.

Returns:

Flag whether all Parameters have identical values or not.

Return type:

bool