Preconditions¶
- graspologic.preconditions.check_argument_types(value, required_types, message)[source]¶
Raises a TypeError if the provided
value
is not one of therequired_types
- Parameters:
- valueAny
The argument to test for valid type
- required_typesUnion[type, Tuple[type, ...]]
A type or a n-ary tuple of types to test for validity
- messagestr
The message to use as the body of the TypeError
- Raises:
- TypeError if the type is not one of the
required_types
- TypeError if the type is not one of the
- Parameters:
- Return type:
None
- graspologic.preconditions.check_optional_argument_types(value, required_types, message)[source]¶
Raises a TypeError if the provided
value
is not one of therequired_types
, unless it is None. A None value is treated as a valid type.- Parameters:
- valueAny
The argument to test for valid type
- required_typesUnion[type, Tuple[type, ...]]
A type or a n-ary tuple of types to test for validity
- messagestr
The message to use as the body of the TypeError
- Raises:
- TypeError if the type is not one of the
required_types
, unless it is None
- TypeError if the type is not one of the
- Parameters:
- Return type:
None
- graspologic.preconditions.check_argument(check, message)[source]¶
Raises a ValueError if the provided check is false
>>> from graspologic import preconditions >>> x = 5 >>> preconditions.check_argument(x < 5, "x must be less than 5") Traceback (most recent call last): ... ValueError: x must be less than 5
- Parameters:
- valueAny
The argument to test for valid type
- required_typesUnion[type, Tuple[type, ...]]
A type or a n-ary tuple of types to test for validity
- messagestr
The message to use as the body of the TypeError
- Raises:
- TypeError if the type is not one of the
required_types
- TypeError if the type is not one of the
- Parameters:
- Return type:
None
- graspologic.preconditions.is_real_weighted(graph, weight_attribute='weight')[source]¶
Checks every edge in
graph
to ascertain whether it has:a
weight_attribute
key in the data dictionary for the edgeif that
weight_attribute
value is a subclass of numbers.Real
If any edge fails this test, it returns
False
, elseTrue
- Parameters:
- graphUnion[nx.Graph, nx.DiGraph]
The networkx graph to test
- weight_attributestr (default="weight")
The edge dictionary data attribute that holds the weight. Default is
weight
.
- Returns:
- bool
True
if every edge has a numericweight_attribute
weight,False
if any edge fails this test
- Parameters:
- Return type: