From 2cbed6cfa7a007fa8853a7bd8cf09303172686c9 Mon Sep 17 00:00:00 2001 From: Mingxin Zheng <18563433+mingxin-zheng@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:40:43 +0800 Subject: [PATCH] Fix test_image_filter test error (#6624) Fixes #6622 . ### Description Add type check to avoid comparing a np.array with a string ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. --------- Signed-off-by: Mingxin Zheng Signed-off-by: Mingxin <18563433+mingxin-zheng@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- monai/transforms/utility/array.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/monai/transforms/utility/array.py b/monai/transforms/utility/array.py index 6c917a9f0a..75b8199314 100644 --- a/monai/transforms/utility/array.py +++ b/monai/transforms/utility/array.py @@ -1641,7 +1641,22 @@ def _check_filter_format(self, filter: str | NdarrayOrTensor | nn.Module, filter "`class 'torch.nn.modules.module.Module'`, `class 'monai.transforms.Transform'`" ) - def _check_kwargs_are_present(self, filter, **kwargs): + def _check_kwargs_are_present(self, filter: str | NdarrayOrTensor | nn.Module, **kwargs: Any) -> None: + """ + Perform sanity checks on the kwargs if the filter contains the required keys. + If the filter is ``gauss``, kwargs should contain ``sigma``. + If the filter is ``savitzky_golay``, kwargs should contain ``order``. + + Args: + filter: A string specifying the filter, a custom filter as ``torch.Tenor`` or ``np.ndarray`` or a ``nn.Module``. + kwargs: additional arguments defining the filter. + + Raises: + KeyError if the filter doesn't contain the requirement key. + """ + + if not isinstance(filter, str): + return if filter == "gauss" and "sigma" not in kwargs.keys(): raise KeyError("`filter='gauss', requires the additional keyword argument `sigma`") if filter == "savitzky_golay" and "order" not in kwargs.keys():