From 9c50291c67795757dfd5ebb0ad803d6a84f21e9b Mon Sep 17 00:00:00 2001 From: jirka Date: Fri, 2 Aug 2024 12:28:24 +0200 Subject: [PATCH] fix missed f-strings --- src/torchmetrics/collections.py | 2 +- src/torchmetrics/detection/mean_ap.py | 2 +- src/torchmetrics/functional/audio/snr.py | 2 +- src/torchmetrics/regression/spearman.py | 2 +- src/torchmetrics/utilities/plot.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/torchmetrics/collections.py b/src/torchmetrics/collections.py index fbcf6a6ac51..85cfe251537 100644 --- a/src/torchmetrics/collections.py +++ b/src/torchmetrics/collections.py @@ -343,7 +343,7 @@ def _compute_and_reduce( elif method_name == "forward": res = m(*args, **m._filter_kwargs(**kwargs)) else: - raise ValueError("method_name should be either 'compute' or 'forward', but got {method_name}") + raise ValueError(f"method_name should be either 'compute' or 'forward', but got {method_name}") result[k] = res _, duplicates = _flatten_dict(result) diff --git a/src/torchmetrics/detection/mean_ap.py b/src/torchmetrics/detection/mean_ap.py index 20c99f094f9..9d4377ed848 100644 --- a/src/torchmetrics/detection/mean_ap.py +++ b/src/torchmetrics/detection/mean_ap.py @@ -416,7 +416,7 @@ def __init__( if max_detection_thresholds is not None and len(max_detection_thresholds) != 3: raise ValueError( "When providing a list of max detection thresholds it should have length 3." - " Got value {len(max_detection_thresholds)}" + f" Got value {len(max_detection_thresholds)}" ) max_det_threshold, _ = torch.sort(torch.tensor(max_detection_thresholds or [1, 10, 100], dtype=torch.int)) self.max_detection_thresholds = max_det_threshold.tolist() diff --git a/src/torchmetrics/functional/audio/snr.py b/src/torchmetrics/functional/audio/snr.py index fb0a4946722..a157061f832 100644 --- a/src/torchmetrics/functional/audio/snr.py +++ b/src/torchmetrics/functional/audio/snr.py @@ -123,7 +123,7 @@ def complex_scale_invariant_signal_noise_ratio(preds: Tensor, target: Tensor, ze if (preds.ndim < 3 or preds.shape[-1] != 2) or (target.ndim < 3 or target.shape[-1] != 2): raise RuntimeError( "Predictions and targets are expected to have the shape (..., frequency, time, 2)," - " but got {preds.shape} and {target.shape}." + f" but got {preds.shape} and {target.shape}." ) preds = preds.reshape(*preds.shape[:-3], -1) diff --git a/src/torchmetrics/regression/spearman.py b/src/torchmetrics/regression/spearman.py index 50e0e22337f..62be592919d 100644 --- a/src/torchmetrics/regression/spearman.py +++ b/src/torchmetrics/regression/spearman.py @@ -88,7 +88,7 @@ def __init__( " For large datasets, this may lead to large memory footprint." ) if not isinstance(num_outputs, int) and num_outputs < 1: - raise ValueError("Expected argument `num_outputs` to be an int larger than 0, but got {num_outputs}") + raise ValueError(f"Expected argument `num_outputs` to be an int larger than 0, but got {num_outputs}") self.num_outputs = num_outputs self.add_state("preds", default=[], dist_reduce_fx="cat") diff --git a/src/torchmetrics/utilities/plot.py b/src/torchmetrics/utilities/plot.py index 12b2ebf338c..4c88c078050 100644 --- a/src/torchmetrics/utilities/plot.py +++ b/src/torchmetrics/utilities/plot.py @@ -326,7 +326,7 @@ def plot_curve( If `curve` does not have 3 elements, being in the wrong format """ if len(curve) < 2: - raise ValueError("Expected 2 or 3 elements in curve but got {len(curve)}") + raise ValueError(f"Expected 2 or 3 elements in curve but got {len(curve)}") x, y = curve[:2] _error_on_missing_matplotlib()