Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Metric.__iter__ by setting it to None #1538

Merged
merged 6 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Extend `EnumStr` raising `ValueError` for invalid value ([#1479](https://github.com/Lightning-AI/metrics/pull/1479))


- Changed `__iter__` method from raising `NotImplementedError` to `TypeError` by setting to `None` ([#1538](https://github.com/Lightning-AI/metrics/pull/1538))

### Deprecated

-
Expand All @@ -64,7 +66,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed `multilabel` in `ExactMatch` ([#1474](https://github.com/Lightning-AI/metrics/pull/1474))



## [0.11.1] - 2023-01-30

### Fixed
Expand Down
4 changes: 1 addition & 3 deletions src/torchmetrics/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,7 @@ def __getnewargs__(self) -> Tuple:
"""Needede method for construction of new metrics __new__ method."""
return (Metric.__str__(self),)

def __iter__(self):
"""Iteration over metrics are not allowed. Use metric collections for nesting metrics."""
raise NotImplementedError("Metrics does not support iteration.")
__iter__ = None


def _neg(x: Tensor) -> Tensor:
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/bases/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def test_custom_availability_check_and_sync_fn():

def test_no_iteration_allowed():
metric = DummyMetric()
with pytest.raises(NotImplementedError, match="Metrics does not support iteration."): # noqa: PT012
with pytest.raises(TypeError, match="'DummyMetric' object is not iterable"): # noqa: PT012
for m in metric:
continue

Expand Down