Skip to content

Commit

Permalink
Fix test_image_filter test error (#6624)
Browse files Browse the repository at this point in the history
Fixes #6622 .

### Description

Add type check to avoid comparing a np.array with a string

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [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 <mingxinz@nvidia.com>
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>
  • Loading branch information
mingxin-zheng and pre-commit-ci[bot] authored Jun 19, 2023
1 parent a89a0af commit 2cbed6c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion monai/transforms/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 2cbed6c

Please sign in to comment.