Skip to content

Commit 2cbed6c

Browse files
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 <!--- 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>
1 parent a89a0af commit 2cbed6c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

monai/transforms/utility/array.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,22 @@ def _check_filter_format(self, filter: str | NdarrayOrTensor | nn.Module, filter
16411641
"`class 'torch.nn.modules.module.Module'`, `class 'monai.transforms.Transform'`"
16421642
)
16431643

1644-
def _check_kwargs_are_present(self, filter, **kwargs):
1644+
def _check_kwargs_are_present(self, filter: str | NdarrayOrTensor | nn.Module, **kwargs: Any) -> None:
1645+
"""
1646+
Perform sanity checks on the kwargs if the filter contains the required keys.
1647+
If the filter is ``gauss``, kwargs should contain ``sigma``.
1648+
If the filter is ``savitzky_golay``, kwargs should contain ``order``.
1649+
1650+
Args:
1651+
filter: A string specifying the filter, a custom filter as ``torch.Tenor`` or ``np.ndarray`` or a ``nn.Module``.
1652+
kwargs: additional arguments defining the filter.
1653+
1654+
Raises:
1655+
KeyError if the filter doesn't contain the requirement key.
1656+
"""
1657+
1658+
if not isinstance(filter, str):
1659+
return
16451660
if filter == "gauss" and "sigma" not in kwargs.keys():
16461661
raise KeyError("`filter='gauss', requires the additional keyword argument `sigma`")
16471662
if filter == "savitzky_golay" and "order" not in kwargs.keys():

0 commit comments

Comments
 (0)