# `skcriteria.utils.object_diff` module¶

Utilities to calculate the difference between two objects.

skcriteria.utils.object_diff.MISSING = <MISSING>

A singleton object used to represent missing values.

skcriteria.utils.object_diff.diff(left, right, **members)[source]

Calculates the difference between two objects, left and right, and returns a Difference object.

Parameters:
• left (object) – The first object to compare.

• right (object) – The second object to compare.

• **members (dict) – Keyword named arguments representing members to compare. The values of the members is the function to compare the members values

Returns:

A Difference object representing the differences between the two objects.

Return type:

Difference

Notes

This function compares the values of corresponding members in the left and right objects. If a member is missing in either object, it is considered a difference. If a member is present in both objects, it is compared using the corresponding comparison function specified in members.

Examples

```>>> obj_a = SomeClass(a=1, b=2)
>>> obj_b = SomeClass(a=1, b=3, c=4)
>>> diff(obj_a, obj_b, a=np.equal, b=np.equal)
<Difference different_types=False members_diff=('b', 'c')>
```
class skcriteria.utils.object_diff.DiffEqualityMixin[source]

Bases: `ABC`

Abstract base class for classes with a diff method.

This class provides methods for comparing objects with a tolerance, allowing for differences within specified limits. It is designed to be used with numpy and pandas equality functions.

Extra methods:

• `aequals`

almost-equals, Check if the two objects are equal within a tolerance.

• `equals(other)`

Return True if the objects are equal.

• `__eq__(other)`

Implement equality comparison.

• `__ne__(other)`

Implement inequality comparison.

abstract diff(other, rtol=1e-05, atol=1e-08, equal_nan=True, check_dtypes=False)[source]

Return the difference between two objects within a tolerance.

This method should be implemented by subclasses to define how differences between objects are calculated.

The tolerance parameters rtol and atol, equal_nan, and check_dtypes are provided to be used by the numpy and pandas equality functions. These parameters allow you to customize the behavior of the equality comparison, such as setting the relative and absolute tolerance for numeric comparisons, considering NaN values as equal, and checking for the data type of the objects being compared.

Notes

The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol are added together to compare against the absolute difference between a and b.

NaNs are treated as equal if they are in the same place and if `equal_nan=True`. Infs are treated as equal if they are in the same place and of the same sign in both arrays.

Parameters:
• other (object) – The object to compare to.

• rtol (float, optional) – The relative tolerance parameter. Default is 1e-05.

• atol (float, optional) – The absolute tolerance parameter. Default is 1e-08.

• equal_nan (bool, optional) – Whether to consider NaN values as equal. Default is True.

• check_dtypes (bool, optional) – Whether to check the data type of the objects. Default is False.

Returns:

The difference between the current and the other object.

Return type:

the_diff

See also

`equals`, `aequals`, `numpy.isclose()`, `numpy.all()`, `numpy.any()`, `numpy.equal()`, `numpy.allclose()`

aequals(other, *, rtol=1e-05, atol=1e-08, equal_nan=True, check_dtypes=False)[source]

Check if the two objects are equal within a tolerance.

All the parameters ara passed to the diff method.

Parameters:
• other (object) – The object to compare to.

• rtol (float, optional) – The relative tolerance parameter. Default is 1e-05.

• atol (float, optional) – The absolute tolerance parameter. Default is 1e-08.

• equal_nan (bool, optional) – Whether to consider NaN values as equal. Default is True.

• check_dtypes (bool, optional) – Whether to check the data type of the objects. Default is False.

Returns:

True if the objects are equal within the specified tolerance, False otherwise.

Return type:

bool

equals(other)[source]

Return True if the objects are equal.

This method calls aquals() without tolerance.

Parameters:

other (`object`) – Other instance to compare.

Returns:

equals – Returns True if the two objects are equals.

Return type:

`bool:py:class:`

See also

`aequals`, `diff.`