AttributeEqualityComparison

giant.utilities.mixin_classes.attribute_equality_comparison:

class giant.utilities.mixin_classes.attribute_equality_comparison.AttributeEqualityComparison[source]

A base class that implements equality comparison based on attributes.

This class provides methods to compare two objects of the same class based on their attributes. It handles comparison of numeric array-like attributes using numpy’s allclose functionality.

Usage:

Inherit from this class to add attribute-based equality comparison to your custom classes.

For example:

comparison_dictionary(other)[source]

Compares each attribute of self to other and stores the result in a dict mapping the attribute to the comparison result.

Each attribute is compared with a call to the internal _value_comparison() which by default uses numpy’s allclose functionality for arraylike objects and standard equality checks for all others. Therefore, if more detailed handling is needed, this _value_comparison() method can be overridden while maintaining the functionality in this method and the class’s equality comparison check.

This assumes that other and self are the same type and have the same attributes.

Parameters:

other (Self) – The other instance to compare with

Returns:

A dictionary mapping attribute names to comparison results

Return type:

dict[str, bool]