Skip to content

Commit

Permalink
Temporarily ignore 2 mypy type-var errors
Browse files Browse the repository at this point in the history
caused by the more precise type annotation of ``numpy.number`` comparison
operators introduced in NumPy 2.1, see:

python/typeshed#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))
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
  • Loading branch information
nsoranzo committed Oct 10, 2024
1 parent f6200f8 commit a03324c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/galaxy/tool_util/verify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,14 @@ def files_contains(file1, file2, attributes=None):
def _multiobject_intersection_over_union(
mask1: "numpy.typing.NDArray", mask2: "numpy.typing.NDArray", repeat_reverse: bool = True
) -> List["numpy.floating"]:
iou_list = []
iou_list: List[numpy.floating] = []
for label1 in numpy.unique(mask1):
cc1 = mask1 == label1
cc1_iou_list = []
cc1_iou_list: List[numpy.floating] = []
for label2 in numpy.unique(mask2[cc1]):
cc2 = mask2 == label2
cc1_iou_list.append(intersection_over_union(cc1, cc2))
iou_list.append(max(cc1_iou_list))
iou_list.append(max(cc1_iou_list)) # type: ignore[type-var, unused-ignore] # https://github.com/python/typeshed/issues/12562
if repeat_reverse:
iou_list.extend(_multiobject_intersection_over_union(mask2, mask1, repeat_reverse=False))
return iou_list
Expand All @@ -475,7 +475,7 @@ def intersection_over_union(mask1: "numpy.typing.NDArray", mask2: "numpy.typing.
if mask1.dtype == bool:
return numpy.logical_and(mask1, mask2).sum() / numpy.logical_or(mask1, mask2).sum()
else:
return min(_multiobject_intersection_over_union(mask1, mask2))
return min(_multiobject_intersection_over_union(mask1, mask2)) # type: ignore[type-var, unused-ignore] # https://github.com/python/typeshed/issues/12562


def get_image_metric(
Expand Down

0 comments on commit a03324c

Please sign in to comment.