Describe the bug
monai/metrics/utils.py declares get_mask_edges() with a deprecation decorator on one of its arguments:
@deprecated_arg(
name="always_return_as_numpy",
since="1.5.0",
removed="1.7.0",
msg_suffix="The option is removed and the return type will always be equal to the input type.",
)
def get_mask_edges(..., always_return_as_numpy: bool = False):
get_edge_surface_distance() in the same module then calls it with that exact deprecated argument (monai/metrics/utils.py:363 on dev):
edges_pred, edges_gt, *areas = get_mask_edges(
y_pred, y, crop=True, spacing=edges_spacing, always_return_as_numpy=False
)
Two consequences:
SurfaceDistanceMetric and HausdorffDistanceMetric both route through get_edge_surface_distance, so every call emits a FutureWarning about an argument the caller never passed and cannot suppress. It shows up in ordinary validation loops.
- The argument is scheduled for removal in 1.7.0, and this internal call site would break that removal.
False is already the parameter default, so the keyword can be dropped with no behaviour change.
To Reproduce
import warnings, torch
from monai.metrics import SurfaceDistanceMetric
a = torch.zeros(1, 1, 32, 32); a[..., :16, :] = 1
b = torch.zeros(1, 1, 32, 32); b[..., :20, :] = 1
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
SurfaceDistanceMetric()(a, b)
print([str(x.message) for x in w if "always_return_as_numpy" in str(x.message)])
This prints one FutureWarning. HausdorffDistanceMetric behaves the same way.
Expected behavior
No deprecation warning, since the caller did not pass a deprecated argument.
Environment
MONAI version: 1.6.0rc1+52.g7f6bf2db
Numpy version: 2.4.6
Pytorch version: 2.13.0
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 7f6bf2db52387d14ef867a79b888e7cc1b81c700
Optional dependencies:
scipy version: 1.17.1
Pillow version: 12.3.0
psutil version: 7.2.2
(others not installed)
System: Darwin
Platform: macOS-26.5.2-arm64-arm-64bit
Python version: 3.11.6
Num physical CPUs: 12
Total physical memory (GB): 32.0
Num GPUs: 0
Has CUDA: False
Additional context
Dropping the keyword leaves results unchanged. Measured over three metric calls on identical inputs:
|
deprecation warnings |
SurfaceDistance |
Hausdorff |
SurfaceDistance reversed |
| before |
3 |
1.173913 |
4.000000 |
1.400000 |
| after |
0 |
1.173913 |
4.000000 |
1.400000 |
This is the same class of warning-hygiene issue as #8931 / #8932, in the same file.
I have a fix and a regression test ready, and would be glad to open a PR.
Describe the bug
monai/metrics/utils.pydeclaresget_mask_edges()with a deprecation decorator on one of its arguments:get_edge_surface_distance()in the same module then calls it with that exact deprecated argument (monai/metrics/utils.py:363ondev):Two consequences:
SurfaceDistanceMetricandHausdorffDistanceMetricboth route throughget_edge_surface_distance, so every call emits aFutureWarningabout an argument the caller never passed and cannot suppress. It shows up in ordinary validation loops.Falseis already the parameter default, so the keyword can be dropped with no behaviour change.To Reproduce
This prints one
FutureWarning.HausdorffDistanceMetricbehaves the same way.Expected behavior
No deprecation warning, since the caller did not pass a deprecated argument.
Environment
Additional context
Dropping the keyword leaves results unchanged. Measured over three metric calls on identical inputs:
This is the same class of warning-hygiene issue as #8931 / #8932, in the same file.
I have a fix and a regression test ready, and would be glad to open a PR.