biogeme.tools.checks module

Utilities to perform various checks

Michel Bierlaire Fri Apr 5 11:09:39 2024

biogeme.tools.checks.assert_sets_equal(name_a, set_a, name_b, set_b)[source]

Raise an informative exception if two sets differ.

Parameters:
  • name_a (str) – Label for the first set (used in the error message).

  • set_a (AbstractSet[TypeVar(T)]) – First set-like collection.

  • name_b (str) – Label for the second set (used in the error message).

  • set_b (AbstractSet[TypeVar(T)]) – Second set-like collection.

Raises:

ValueError – If the two sets do not contain exactly the same elements.

Return type:

None

biogeme.tools.checks.check_consistency_of_named_dicts(named_dicts)[source]

Verify that all dictionaries have the same set of keys. If not, report the inconsistencies.

Parameters:

named_dicts (dict[str, dict[Any, Any]]) – A dictionary where each key is a name (str) and each value is a dictionary to check.

Return type:

tuple[bool, str | None]

Returns:

True if keys are consistent across all dictionaries, False otherwise. If not consistent, returns a report detailing the inconsistencies.

biogeme.tools.checks.validate_dict_types(parameter, name, value_type, key_type=<class 'int'>)[source]

Validate the types of keys and values in a dictionary.

Parameters:
  • parameter (dict) – The dictionary parameter to validate.

  • name (str) – The name of the parameter for error messages.

  • value_type (type) – The expected type of the dictionary values.

  • key_type (type) – The expected type of the dictionary keys. Default is int.

Raises:

TypeError – If key or value types do not match expectations.

Return type:

None