From 3b6b9a2471f51b504fac54b8098b2dd1f96f1b3b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:15:48 +0100 Subject: [PATCH] build(deps): bump mypy from 1.11.2 to 1.13.0 in /requirements (#2808) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jirka B Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com> (cherry picked from commit 421e028b9715636ca9e325ad692e21b5220e4f56) --- requirements/typing.txt | 2 +- src/torchmetrics/detection/_mean_ap.py | 6 +++--- src/torchmetrics/functional/audio/pit.py | 2 +- src/torchmetrics/wrappers/tracker.py | 11 ++++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/requirements/typing.txt b/requirements/typing.txt index 01c6897fa9c..449ff685fa6 100644 --- a/requirements/typing.txt +++ b/requirements/typing.txt @@ -1,4 +1,4 @@ -mypy ==1.11.2 +mypy ==1.13.0 torch ==2.5.0 types-PyYAML diff --git a/src/torchmetrics/detection/_mean_ap.py b/src/torchmetrics/detection/_mean_ap.py index fd342608360..73df4a41d91 100644 --- a/src/torchmetrics/detection/_mean_ap.py +++ b/src/torchmetrics/detection/_mean_ap.py @@ -849,9 +849,9 @@ def __calculate_recall_precision_scores( inds = torch.searchsorted(rc, rec_thresholds.to(rc.device), right=False) num_inds = inds.argmax() if inds.max() >= tp_len else num_rec_thrs - inds = inds[:num_inds] # type: ignore[misc] - prec[:num_inds] = pr[inds] # type: ignore[misc] - score[:num_inds] = det_scores_sorted[inds] # type: ignore[misc] + inds = inds[:num_inds] + prec[:num_inds] = pr[inds] + score[:num_inds] = det_scores_sorted[inds] precision[idx, :, idx_cls, idx_bbox_area, idx_max_det_thresholds] = prec scores[idx, :, idx_cls, idx_bbox_area, idx_max_det_thresholds] = score diff --git a/src/torchmetrics/functional/audio/pit.py b/src/torchmetrics/functional/audio/pit.py index 90c4afb01f9..8fa186299f9 100644 --- a/src/torchmetrics/functional/audio/pit.py +++ b/src/torchmetrics/functional/audio/pit.py @@ -182,7 +182,7 @@ def permutation_invariant_training( metric_of_ps = metric_func(ppreds, ptarget) metric_of_ps = torch.mean(metric_of_ps.reshape(batch_size, len(perms), -1), dim=-1) # find the best metric and best permutation - best_metric, best_indexes = eval_op(metric_of_ps, dim=1) # type: ignore[call-overload] + best_metric, best_indexes = eval_op(metric_of_ps, dim=1) best_indexes = best_indexes.detach() best_perm = perms[best_indexes, :] return best_metric, best_perm diff --git a/src/torchmetrics/wrappers/tracker.py b/src/torchmetrics/wrappers/tracker.py index 554902d1092..c1fe9957b1b 100644 --- a/src/torchmetrics/wrappers/tracker.py +++ b/src/torchmetrics/wrappers/tracker.py @@ -219,7 +219,8 @@ def best_metric( ) -> Union[ None, float, - Tuple[float, int], + Tensor, + Tuple[Union[int, float, Tensor], Union[int, float, Tensor]], Tuple[None, None], Dict[str, Union[float, None]], Tuple[Dict[str, Union[float, None]], Dict[str, Union[int, None]]], @@ -260,7 +261,7 @@ def best_metric( if isinstance(self._base_metric, Metric): fn = torch.max if self.maximize else torch.min try: - value, idx = fn(res, 0) # type: ignore[call-overload] + value, idx = fn(res, 0) if return_step: return value.item(), idx.item() return value.item() @@ -277,11 +278,11 @@ def best_metric( else: # this is a metric collection maximize = self.maximize if isinstance(self.maximize, list) else len(res) * [self.maximize] - value, idx = {}, {} + value, idx = {}, {} # type: ignore[assignment] for i, (k, v) in enumerate(res.items()): try: fn = torch.max if maximize[i] else torch.min - out = fn(v, 0) # type: ignore[call-overload] + out = fn(v, 0) value[k], idx[k] = out[0].item(), out[1].item() except (ValueError, RuntimeError) as error: # noqa: PERF203 # todo rank_zero_warn( @@ -290,7 +291,7 @@ def best_metric( "Returning `None` instead.", UserWarning, ) - value[k], idx[k] = None, None + value[k], idx[k] = None, None # type: ignore[assignment] if return_step: return value, idx