Skip to content

Commit a429051

Browse files
committed
Use MONAI deprecated decorator
Signed-off-by: Soumya Snigdha Kundu <[email protected]>
1 parent b69af40 commit a429051

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

monai/apps/deepedit/transforms.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from monai.data import MetaTensor
2525
from monai.networks.layers import GaussianFilter
2626
from monai.transforms.transform import MapTransform, Randomizable, Transform
27-
from monai.utils import min_version, optional_import
27+
from monai.utils import deprecated, min_version, optional_import
2828

2929
measure, _ = optional_import("skimage.measure", "0.14.2", min_version)
3030

@@ -155,26 +155,18 @@ def __call__(self, data: Mapping[Hashable, np.ndarray]) -> dict[Hashable, np.nda
155155
return d
156156

157157

158+
@deprecated(since="1.6", removed="1.8", msg_suffix="Use `RemapLabelsToSequentiald` instead.")
158159
class NormalizeLabelsInDatasetd(RemapLabelsToSequentiald):
159160
"""
160-
.. deprecated:: 1.5.0
161-
`NormalizeLabelsInDatasetd` is deprecated. Use :class:`RemapLabelsToSequentiald` instead.
161+
.. deprecated:: 1.6.0
162+
`NormalizeLabelsInDatasetd` is deprecated and will be removed in version 1.8.0.
163+
Use :class:`RemapLabelsToSequentiald` instead.
162164
163165
This class is maintained for backward compatibility. Please use RemapLabelsToSequentiald
164166
which better describes the transform's functionality.
165167
"""
166168

167-
def __init__(
168-
self, keys: KeysCollection, label_names: dict[str, int] | None = None, allow_missing_keys: bool = False
169-
):
170-
warnings.warn(
171-
"NormalizeLabelsInDatasetd is deprecated and will be removed in a future version. "
172-
"Please use RemapLabelsToSequentiald instead, which better describes what the transform does: "
173-
"remapping label values to sequential indices (0, 1, 2, 3, ...).",
174-
DeprecationWarning,
175-
stacklevel=2,
176-
)
177-
super().__init__(keys, label_names, allow_missing_keys)
169+
pass
178170

179171

180172
class SingleLabelSelectiond(MapTransform):

tests/apps/deepedit/test_deepedit_transforms.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,26 @@ def test_multiple_labels(self):
332332
self.assertEqual(result["label_names"], {"background": 0, "kidney": 1, "liver": 2, "spleen": 3})
333333

334334
def test_deprecated_name_warning(self):
335-
"""Test that using the deprecated name raises a warning"""
335+
"""Test that using the deprecated name raises a warning when version >= 1.6"""
336336
import warnings
337337

338+
from monai.utils import deprecated
339+
340+
# Create a test class with version_val to simulate version 1.6
341+
@deprecated(since="1.6", removed="1.8", msg_suffix="Use `RemapLabelsToSequentiald` instead.", version_val="1.6")
342+
class TestDeprecatedClass(RemapLabelsToSequentiald):
343+
pass
344+
338345
data = {"label": np.array([[[0, 1]]])}
339346

340347
with warnings.catch_warnings(record=True) as w:
341348
warnings.simplefilter("always")
342-
transform = NormalizeLabelsInDatasetd(keys="label", label_names={"spleen": 1, "background": 0})
343-
_ = transform(data) # Call to trigger the warning
349+
transform = TestDeprecatedClass(keys="label", label_names={"spleen": 1, "background": 0})
350+
_ = transform(data) # Invoke the transform to confirm functionality
344351

345-
# Check that a deprecation warning was raised
352+
# Check that a deprecation warning was raised (deprecated decorator uses FutureWarning)
346353
self.assertEqual(len(w), 1)
347-
self.assertTrue(issubclass(w[0].category, DeprecationWarning))
354+
self.assertTrue(issubclass(w[0].category, FutureWarning))
348355
self.assertIn("RemapLabelsToSequentiald", str(w[0].message))
349356

350357

0 commit comments

Comments
 (0)