Skip to content

Commit

Permalink
[BC] Rename to actual and expected (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
durandtibo authored Feb 29, 2024
1 parent feb4236 commit 8c22b78
Show file tree
Hide file tree
Showing 65 changed files with 930 additions and 930 deletions.
12 changes: 6 additions & 6 deletions docs/docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ The following example shows how to use a custom `BaseEqualityTester`.
>>> from coola.equality import EqualityConfig
>>> from coola.equality.testers import BaseEqualityTester
>>> class MyCustomEqualityTester(BaseEqualityTester):
... def equal(self, object1: Any, object2: Any, config: EqualityConfig) -> bool:
... return object1 is object2
... def equal(self, actual: Any, expected: Any, config: EqualityConfig) -> bool:
... return actual is expected
...
>>> objects_are_equal([1, 2, 3], (1, 2, 3), tester=MyCustomEqualityTester())
False
Expand Down Expand Up @@ -91,11 +91,11 @@ Then, you need to add the `BaseEqualityComparator` to `EqualityTester`.
... def clone(self) -> "MyCustomStrEqualityOperator":
... return self.__class__()
...
... def equal(self, object1: str, object2: Any, config: EqualityConfig) -> bool:
... def equal(self, actual: str, expected: Any, config: EqualityConfig) -> bool:
... # You can add code to check the type and to log a message to indicate
... # the difference between the objects if any. To keep this example
... # simple, this part is skipped.
... return object1 in object2
... return actual in expected
...
>>> # Step 2: add the new equality comparator to EqualityTester
>>> tester = EqualityTester.local_copy()
Expand Down Expand Up @@ -129,11 +129,11 @@ the new equality comparator is added.
... def clone(self) -> "MyCustomMappingEqualityComparator":
... return self.__class__()
...
... def equal(self, object1: Mapping, object2: Any, config: EqualityConfig) -> bool:
... def equal(self, actual: Mapping, expected: Any, config: EqualityConfig) -> bool:
... # You can add code to check the type and to log a message to indicate
... # the difference between the objects if any. To keep this example
... # simple, this part is skipped.
... return object1 is object2
... return actual is expected
...
>>> tester = EqualityTester.local_copy()
>>> tester.add_comparator(
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ False

```textmate
INFO:coola.comparators.torch_:torch.Tensors are different
object1=
actual=
tensor([[1., 1., 1.],
[1., 1., 1.]])
object2=
expected=
tensor([[0., 0., 0.],
[0., 0., 0.]])
INFO:coola.comparators.equality:The mappings have a different value for the key 'torch':
Expand Down Expand Up @@ -245,10 +245,10 @@ False

```textmate
INFO:coola.comparators.torch_:torch.Tensors are different
object1=
actual=
tensor([[1., 1., 1.],
[1., 1., 1.]])
object2=
expected=
tensor([[1.0001, 1.0001, 1.0001],
[1.0001, 1.0001, 1.0001]])
INFO:coola.comparators.allclose:The mappings have a different value for the key torch:
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The current supported types are:
By default, two objects are equal if:

- they have the same type
- they are equal i.e. `object1 == object2` returns `True`
- they are equal i.e. `actual == expected` returns `True`

**Example**

Expand Down Expand Up @@ -306,7 +306,7 @@ The tolerance is only used for numbers (see below).
By default, two objects are equal if:

- they have the same type
- they are equal i.e. `object1 == object2` returns `True`
- they are equal i.e. `actual == expected` returns `True`

**Example**

Expand Down
20 changes: 10 additions & 10 deletions src/coola/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


def objects_are_allclose(
object1: Any,
object2: Any,
actual: Any,
expected: Any,
*,
rtol: float = 1e-5,
atol: float = 1e-8,
Expand All @@ -26,8 +26,8 @@ def objects_are_allclose(
r"""Indicate if two objects are equal within a tolerance.
Args:
object1: Specifies the first object to compare.
object2: Specifies the second object to compare.
actual: Specifies the actual input.
expected: Specifies the expected input.
rtol: Specifies the relative tolerance parameter.
atol: Specifies the absolute tolerance parameter.
equal_nan: If ``True``, then two ``NaN``s will be considered
Expand Down Expand Up @@ -71,12 +71,12 @@ def objects_are_allclose(
config = EqualityConfig(
tester=tester, show_difference=show_difference, equal_nan=equal_nan, atol=atol, rtol=rtol
)
return tester.equal(object1, object2, config)
return tester.equal(actual, expected, config)


def objects_are_equal(
object1: Any,
object2: Any,
actual: Any,
expected: Any,
*,
equal_nan: bool = False,
show_difference: bool = False,
Expand All @@ -85,8 +85,8 @@ def objects_are_equal(
r"""Indicate if two objects are equal or not.
Args:
object1: Specifies the first object to compare.
object2: Specifies the second object to compare.
actual: Specifies the actual input.
expected: Specifies the expected input.
equal_nan: If ``True``, then two ``NaN``s will be considered
as equal.
show_difference: If ``True``, it shows a difference between
Expand Down Expand Up @@ -116,4 +116,4 @@ def objects_are_equal(
"""
tester = tester or EqualityTester()
config = EqualityConfig(tester=tester, show_difference=show_difference, equal_nan=equal_nan)
return tester.equal(object1, object2, config)
return tester.equal(actual, expected, config)
6 changes: 3 additions & 3 deletions src/coola/equality/comparators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def clone(self) -> BaseEqualityComparator:
"""

@abstractmethod
def equal(self, object1: T, object2: Any, config: EqualityConfig) -> bool:
def equal(self, actual: T, expected: Any, config: EqualityConfig) -> bool:
r"""Indicate if two objects are equal or not.
Args:
object1: Specifies the first object to compare.
object2: Specifies the second object to compare.
actual: Specifies the actual input.
expected: Specifies the expected input.
config: Specifies the equality configuration.
Returns:
Expand Down
8 changes: 4 additions & 4 deletions src/coola/equality/comparators/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> MappingEqualityComparator:
return self.__class__()

def equal(self, object1: Mapping, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: Mapping, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


class SequenceEqualityComparator(BaseEqualityComparator[Sequence]):
Expand Down Expand Up @@ -93,8 +93,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> SequenceEqualityComparator:
return self.__class__()

def equal(self, object1: Sequence, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: Sequence, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
4 changes: 2 additions & 2 deletions src/coola/equality/comparators/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> DefaultEqualityComparator:
return self.__class__()

def equal(self, object1: Any, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: Any, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
4 changes: 2 additions & 2 deletions src/coola/equality/comparators/jax_.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> JaxArrayEqualityComparator:
return self.__class__()

def equal(self, object1: jnp.ndarray, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: jnp.ndarray, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
8 changes: 4 additions & 4 deletions src/coola/equality/comparators/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> NumpyArrayEqualityComparator:
return self.__class__()

def equal(self, object1: Any, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: Any, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


class NumpyMaskedArrayEqualityComparator(BaseEqualityComparator[np.ma.MaskedArray]):
Expand Down Expand Up @@ -110,8 +110,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> NumpyMaskedArrayEqualityComparator:
return self.__class__()

def equal(self, object1: np.ma.MaskedArray, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: np.ma.MaskedArray, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
8 changes: 4 additions & 4 deletions src/coola/equality/comparators/pandas_.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> PandasDataFrameEqualityComparator:
return self.__class__()

def equal(self, object1: pandas.DataFrame, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: pandas.DataFrame, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


class PandasSeriesEqualityComparator(BaseEqualityComparator[pandas.Series]):
Expand Down Expand Up @@ -107,8 +107,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> PandasSeriesEqualityComparator:
return self.__class__()

def equal(self, object1: pandas.Series, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: pandas.Series, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
8 changes: 4 additions & 4 deletions src/coola/equality/comparators/polars_.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> PolarsDataFrameEqualityComparator:
return self.__class__()

def equal(self, object1: polars.DataFrame, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: polars.DataFrame, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


class PolarsSeriesEqualityComparator(BaseEqualityComparator[polars.Series]):
Expand Down Expand Up @@ -107,8 +107,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> PolarsSeriesEqualityComparator:
return self.__class__()

def equal(self, object1: polars.Series, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: polars.Series, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
4 changes: 2 additions & 2 deletions src/coola/equality/comparators/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> ScalarEqualityComparator:
return self.__class__()

def equal(self, object1: Any, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: Any, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
8 changes: 4 additions & 4 deletions src/coola/equality/comparators/torch_.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def clone(self) -> TorchPackedSequenceEqualityComparator:
return self.__class__()

def equal(
self, object1: torch.nn.utils.rnn.PackedSequence, object2: Any, config: EqualityConfig
self, actual: torch.nn.utils.rnn.PackedSequence, expected: Any, config: EqualityConfig
) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
return self._handler.handle(actual=actual, expected=expected, config=config)


class TorchTensorEqualityComparator(BaseEqualityComparator[torch.Tensor]):
Expand Down Expand Up @@ -118,8 +118,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> TorchTensorEqualityComparator:
return self.__class__()

def equal(self, object1: torch.Tensor, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: torch.Tensor, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
12 changes: 6 additions & 6 deletions src/coola/equality/comparators/xarray_.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> XarrayDataArrayEqualityComparator:
return self.__class__()

def equal(self, object1: xr.DataArray, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: xr.DataArray, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


class XarrayDatasetEqualityComparator(BaseEqualityComparator[xr.Dataset]):
Expand Down Expand Up @@ -122,8 +122,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> XarrayDatasetEqualityComparator:
return self.__class__()

def equal(self, object1: xr.Dataset, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: xr.Dataset, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


class XarrayVariableEqualityComparator(BaseEqualityComparator[xr.Variable]):
Expand Down Expand Up @@ -168,8 +168,8 @@ def __eq__(self, other: object) -> bool:
def clone(self) -> XarrayVariableEqualityComparator:
return self.__class__()

def equal(self, object1: xr.Variable, object2: Any, config: EqualityConfig) -> bool:
return self._handler.handle(object1=object1, object2=object2, config=config)
def equal(self, actual: xr.Variable, expected: Any, config: EqualityConfig) -> bool:
return self._handler.handle(actual=actual, expected=expected, config=config)


def get_type_comparator_mapping() -> dict[type, BaseEqualityComparator]:
Expand Down
14 changes: 7 additions & 7 deletions src/coola/equality/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ def chain(self, handler: BaseEqualityHandler) -> BaseEqualityHandler:
return handler

@abstractmethod
def handle(self, object1: Any, object2: Any, config: EqualityConfig) -> bool:
def handle(self, actual: Any, expected: Any, config: EqualityConfig) -> bool:
r"""Return the equality result between the two input objects.
Args:
object1: Specifies the first object to compare.
object2: Specifies the second object to compare.
actual: Specifies the actual input.
expected: Specifies the expected input.
config: Specifies the equality configuration.
Returns:
Expand Down Expand Up @@ -132,12 +132,12 @@ def next_handler(self) -> BaseEqualityHandler | None:
"""The next handler."""
return self._next_handler

def _handle_next(self, object1: Any, object2: Any, config: EqualityConfig) -> bool:
def _handle_next(self, actual: Any, expected: Any, config: EqualityConfig) -> bool:
r"""Return the output from the next handler.
Args:
object1: Specifies the first object to compare.
object2: Specifies the second object to compare.
actual: Specifies the actual input.
expected: Specifies the expected input.
config: Specifies the equality configuration.
Returns:
Expand All @@ -149,7 +149,7 @@ def _handle_next(self, object1: Any, object2: Any, config: EqualityConfig) -> bo
if not self._next_handler:
msg = "next handler is not defined"
raise RuntimeError(msg)
return self._next_handler.handle(object1=object1, object2=object2, config=config)
return self._next_handler.handle(actual=actual, expected=expected, config=config)

def set_next_handler(self, handler: BaseEqualityHandler) -> None:
if not isinstance(handler, BaseEqualityHandler):
Expand Down
8 changes: 4 additions & 4 deletions src/coola/equality/handlers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class SameDataHandler(AbstractEqualityHandler):
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__)

def handle(self, object1: SupportsData, object2: SupportsData, config: EqualityConfig) -> bool:
if not config.tester.equal(object1.data, object2.data, config):
def handle(self, actual: SupportsData, expected: SupportsData, config: EqualityConfig) -> bool:
if not config.tester.equal(actual.data, expected.data, config):
if config.show_difference:
logger.info(f"objects have different data: {object1.data} vs {object2.data}")
logger.info(f"objects have different data: {actual.data} vs {expected.data}")
return False
return self._handle_next(object1=object1, object2=object2, config=config)
return self._handle_next(actual=actual, expected=expected, config=config)
Loading

0 comments on commit 8c22b78

Please sign in to comment.