Coola: Object Equality Checker
Coola is a Python library designed for robustly checking equality between two complex or nested Python objects. It provides a flexible mechanism to compare various data structures, going beyond Python's default `==` operator for deep and custom comparisons. The library is actively maintained with frequent minor releases, ensuring ongoing development and improvements.
Warnings
- breaking In version 1.1.0, the `coola.utils.imports` module was converted into a package, leading to a reorganization of its functions into different modules. Code that directly imports from or patches `coola.utils.imports` will break.
- breaking Version 1.0.0 introduced significant API alignment across all functionalities. While aiming for consistency, this release may contain breaking changes for users upgrading from pre-1.0.0 versions, particularly regarding naming conventions and usage patterns.
- gotcha When comparing floating-point numbers in nested structures, direct equality checks can fail due to precision issues. While `coola` offers advanced comparison, ensure you configure appropriate tolerances (e.g., `atol` or `rtol` parameters if available in the specific comparison function) for floats to avoid unexpected `False` results.
- gotcha By default, `coola` might perform strict type and value comparisons. For custom classes or objects with complex internal states, you might need to register custom comparison logic or ensure your `__eq__` and `__hash__` methods are correctly implemented for `coola` to interpret equality as intended.
Install
-
pip install coola
Imports
- objects_are_equal
from coola.equality import objects_are_equal
Quickstart
from coola.equality import objects_are_equal
obj1 = {'a': 1, 'b': [2, {'c': 3}], 'd': {'e': 4}}
obj2 = {'d': {'e': 4}, 'b': [2, {'c': 3}], 'a': 1}
obj3 = {'a': 1, 'b': [2, {'c': 99}], 'd': {'e': 4}}
# Deep comparison of two equal nested objects (order-independent for dicts)
print(f"obj1 == obj2: {objects_are_equal(obj1, obj2)}")
# Deep comparison of two different nested objects
print(f"obj1 == obj3: {objects_are_equal(obj1, obj3)}")
# Comparison with a custom tolerance for floats (example for potential feature)
float_obj1 = {'x': 1.000000001}
float_obj2 = {'x': 1.000000002}
# For demonstration, assume a tolerance parameter, actual API might vary
# print(f"float_obj1 == float_obj2 with tolerance: {objects_are_equal(float_obj1, float_obj2, atol=1e-8)}")