-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] improved
deep_equals
utility - plugins for custom types (#238)
This PR improves the `deep_equals` utility by introducing the ability to provide custom plugins. Ultimately, this enables more flexibility in soft dependencies for data containers such as `polars` (see, e.g., sktime/sktime#5423) throughout the `sktime` package ecosystem, as `deep_equals` is used for extrinsic testing and validity checking. Similarly, the `ForecastingHorizon` check should be moved as a plugin into `sktime`. In addition, makes the following changes: * splits up the `deep_equals` file into a module with multiple files Depends on #239.
- Loading branch information
Showing
5 changed files
with
221 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# copyright: skbase developers, BSD-3-Clause License (see LICENSE file) | ||
"""Module for nested equality checking.""" | ||
from skbase.utils.deep_equals._deep_equals import deep_equals | ||
|
||
__all__ = [ | ||
"deep_equals", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Common utility functions for skbase.utils.deep_equals.""" | ||
|
||
|
||
def _ret(is_equal, msg="", string_arguments: list = None, return_msg=False): | ||
"""Return is_equal and msg, formatted with string_arguments if return_msg=True. | ||
Parameters | ||
---------- | ||
is_equal : bool | ||
msg : str, optional, default="" | ||
message to return if is_equal=False | ||
string_arguments : list, optional, default=None | ||
list of arguments to format msg with | ||
Returns | ||
------- | ||
is_equal : bool | ||
identical to input ``is_equal``, always returned | ||
msg : str, only returned if return_msg=True | ||
if ``is_equal=True``, ``msg`` is always ``""`` | ||
if ``is_equal=False``, ``msg`` is formatted with ``string_arguments`` | ||
via ``msg.format(*string_arguments)`` | ||
""" | ||
if return_msg: | ||
if is_equal: | ||
msg = "" | ||
elif isinstance(string_arguments, (list, tuple)) and len(string_arguments) > 0: | ||
msg = msg.format(*string_arguments) | ||
return is_equal, msg | ||
else: | ||
return is_equal | ||
|
||
|
||
def _make_ret(return_msg): | ||
"""Curry _ret with return_msg.""" | ||
|
||
def ret(is_equal, msg, string_arguments=None): | ||
return _ret(is_equal, msg, string_arguments, return_msg) | ||
|
||
return ret |
Oops, something went wrong.