From cb069ef952162d4c57e9dae3c13636ea3764342b Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Fri, 30 Aug 2024 18:16:28 +0100 Subject: [PATCH] Temporarily ignore 2 mypy type-var errors caused by the more precise type annotation of ``numpy.number`` comparison operators introduced in NumPy 2.1, see: https://github.com/python/typeshed/issues/12562 Fix the following errors when running test_galaxy_packages on Python >=3.10: ``` galaxy/tool_util/verify/__init__.py:503: error: Value of type variable "SupportsRichComparisonT" of "max" cannot be "floating[Any]" [type-var] iou_list.append(max(cc1_iou_list)) ^~~~~~~~~~~~~~~~~ galaxy/tool_util/verify/__init__.py:532: error: Value of type variable "SupportsRichComparisonT" of "min" cannot be "floating[Any]" [type-var] return min(_multiobject_intersection_over_union(mask1, mask2, pin_labels)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` --- lib/galaxy/tool_util/verify/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/tool_util/verify/__init__.py b/lib/galaxy/tool_util/verify/__init__.py index 4096c4c9d865..85a55fe03fdd 100644 --- a/lib/galaxy/tool_util/verify/__init__.py +++ b/lib/galaxy/tool_util/verify/__init__.py @@ -471,8 +471,8 @@ def files_contains(file1, file2, attributes=None): def _singleobject_intersection_over_union( - mask1: "numpy.typing.NDArray", - mask2: "numpy.typing.NDArray", + mask1: "numpy.typing.NDArray[numpy.bool]", + mask2: "numpy.typing.NDArray[numpy.bool]", ) -> "numpy.floating": return numpy.logical_and(mask1, mask2).sum() / numpy.logical_or(mask1, mask2).sum() @@ -483,7 +483,7 @@ def _multiobject_intersection_over_union( pin_labels: Optional[List[int]] = None, repeat_reverse: bool = True, ) -> List["numpy.floating"]: - iou_list = [] + iou_list: List[numpy.floating] = [] for label1 in numpy.unique(mask1): cc1 = mask1 == label1 @@ -494,13 +494,13 @@ def _multiobject_intersection_over_union( # Otherwise, use the object with the largest IoU value, excluding the pinned labels. else: - cc1_iou_list = [] + cc1_iou_list: List[numpy.floating] = [] for label2 in numpy.unique(mask2[cc1]): if pin_labels is not None and label2 in pin_labels: continue cc2 = mask2 == label2 cc1_iou_list.append(_singleobject_intersection_over_union(cc1, cc2)) - iou_list.append(max(cc1_iou_list)) + iou_list.append(max(cc1_iou_list)) # type: ignore[type-var] # https://github.com/python/typeshed/issues/12562 if repeat_reverse: iou_list.extend(_multiobject_intersection_over_union(mask2, mask1, pin_labels, repeat_reverse=False)) @@ -511,7 +511,7 @@ def _multiobject_intersection_over_union( def intersection_over_union( mask1: "numpy.typing.NDArray", mask2: "numpy.typing.NDArray", pin_labels: Optional[List[int]] = None ) -> "numpy.floating": - """Compute the intersection over union (IoU) for the objects in two masks containing lables. + """Compute the intersection over union (IoU) for the objects in two masks containing labels. The IoU is computed for each uniquely labeled image region (object), and the overall minimum value is returned (i.e. the worst value). To compute the IoU for each object, the corresponding object in the other mask needs to be determined. @@ -529,7 +529,7 @@ def intersection_over_union( count = sum(label in mask for mask in (mask1, mask2)) count_str = {1: "one", 2: "both"} assert count == 2, f"Label {label} is pinned but missing in {count_str[2 - count]} of the images." - return min(_multiobject_intersection_over_union(mask1, mask2, pin_labels)) + return min(_multiobject_intersection_over_union(mask1, mask2, pin_labels)) # type: ignore[type-var] # https://github.com/python/typeshed/issues/12562 def _parse_label_list(label_list_str: Optional[str]) -> List[int]: