Skip to content

Commit

Permalink
Add type check on maximize in MetricTracker (#1430)
Browse files Browse the repository at this point in the history
Fixes #1428
  • Loading branch information
ValerianRey committed Jan 9, 2023
1 parent 107dbfd commit 7b505ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

-
- Fixed type checking on the `maximize` parameter at the initialization of `MetricTracker` ([#1428](https://github.com/Lightning-AI/metrics/issues/1428))


## [0.11.0] - 2022-11-30
Expand Down
2 changes: 2 additions & 0 deletions src/torchmetrics/wrappers/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def __init__(self, metric: Union[Metric, MetricCollection], maximize: Union[bool
raise ValueError("Argument `maximize` should either be a single bool or list of bool")
if isinstance(maximize, list) and isinstance(metric, MetricCollection) and len(maximize) != len(metric):
raise ValueError("The len of argument `maximize` should match the length of the metric collection")
if isinstance(metric, Metric) and not isinstance(maximize, bool):
raise ValueError("Argument `maximize` should be a single bool when `metric` is a single Metric")
self.maximize = maximize

self._increment_called = False
Expand Down
5 changes: 5 additions & 0 deletions tests/unittests/wrappers/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def test_raises_error_on_wrong_input():
):
MetricTracker(MetricCollection([MeanAbsoluteError(), MeanSquaredError()]), maximize=[False, False, False])

with pytest.raises(
ValueError, match="Argument `maximize` should be a single bool when `metric` is a single Metric"
):
MetricTracker(MeanAbsoluteError(), maximize=[False])


@pytest.mark.parametrize(
"method, method_input",
Expand Down

0 comments on commit 7b505ff

Please sign in to comment.