TidalPy.utilities package

Subpackages

Submodules

TidalPy.utilities.dictionary_utils module

TidalPy.utilities.dictionary_utils.nested_get(input_dict: dict, nested_keys: str | int | float | List[str | int | float] | Tuple[str | int | float, ...], default: Any = None, raiseon_nolocate: bool = False) Any[source]

Returns a value from a series of nested dictionaries given a list of keys

Parameters:
  • input_dict (dict) – Dictionary containing nested dictionary(ies)

  • nested_keys (Union[PossibleKeyType, List[PossibleKeyType, ...], Tuple[PossibleKeyType, ...]]) – List of keys to search the dictionary with.

  • default (Any = None) – Default value if key can’t be found

  • raiseon_nolocate (bool = False) – If key can’t be found and this is True then a KeyError exception will be raised.

Returns:

value – Value stored in the nested dictionaries

Return type:

Any

TidalPy.utilities.dictionary_utils.nested_merge(old_dict: dict, new_dict: dict, make_copies: bool = True) dict[source]
Replaces values in an old dict with values in a new dict, but does not overwrite nested dicts. Instead it

will perform the same type of replacement on each nested dict.

Parameters:
  • old_dict (dict) – Old dictionary that will have some values replaced.

  • new_dict (dict) – New dictionary whose values will override any values in old_dict.

  • make_copies (bool = True) –

    If True, then copies will be made of all dictionaries so that later mutations don’t propagate to the combined

    dict.

Returns:

combo_dict – Dictionary made from combining old and new dicts.

Return type:

dict

TidalPy.utilities.dictionary_utils.nested_place(replacement_value: Any, dict_to_overwrite: dict, nested_keys: str | int | float | List[str | int | float] | Tuple[str | int | float, ...], make_copy: bool = False, retain_old_value: bool = False) dict[source]

Replaces a nested-dictionary value based on a list of keys.

Parameters:
  • replacement_value (Any) – New value that will replace any old values.

  • dict_to_overwrite (dict) – Dictionary whose value will be replaced.

  • nested_keys (Union[PossibleKeyType, List[PossibleKeyType, ...], Tuple[PossibleKeyType, ...]]) – List-like container of keys required to get to the location of the replacement value. The last key’s value will be replaced by replacement_value.

  • make_copy (bool = False) – If true then a new dictionary will be made (copy of dict_to_overwrite). In-place (mutation) replacement will not take place.

  • retain_old_value (bool = False) – If true then any old value found will be saved with the key “<name of last key in list>_OLD”

Returns:

dict_to_overwrite – Dictionary after the replacement has been made. Note: if make_copy is True then this will not be the same dictionary reference that was originally passed in.

Return type:

dict

TidalPy.utilities.types module

TidalPy.utilities.types_x module