Skip to content

Commit 0ce3977

Browse files
authored
Fix todo in pycocotools (#13182)
Adds numpy types. All the types were already there as comments.
1 parent 43f637b commit 0ce3977

File tree

4 files changed

+32
-50
lines changed

4 files changed

+32
-50
lines changed

stubs/pycocotools/METADATA.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
version = "2.0.*"
22
upstream_repository = "https://github.com/ppwwyyxx/cocoapi"
3+
requires = ["numpy>=2.0.0rc1; python_version>='3.9'"]
4+
# numpy>=2.0.0 requires Python >=3.9
5+
requires_python = ">=3.9"

stubs/pycocotools/pycocotools/coco.pyi

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
from _typeshed import Incomplete
21
from collections.abc import Collection, Sequence
32
from pathlib import Path
43
from typing import Generic, Literal, TypedDict, TypeVar, overload
54
from typing_extensions import TypeAlias
65

7-
from . import _EncodedRLE
6+
import numpy as np
7+
import numpy.typing as npt
88

9-
# TODO: Use numpy types when #5768 is resolved.
10-
# import numpy as np
11-
# import numpy.typing as npt
9+
from . import _EncodedRLE
1210

13-
PYTHON_VERSION: Incomplete
14-
_NDArray: TypeAlias = Incomplete
11+
PYTHON_VERSION: int
1512

1613
class _Image(TypedDict):
1714
id: int
@@ -82,13 +79,11 @@ class COCO:
8279
def showAnns(self, anns: Sequence[_Annotation], draw_bbox: bool = False) -> None: ...
8380
def loadRes(self, resFile: str) -> COCO: ...
8481
def download(self, tarDir: str | None = None, imgIds: Collection[int] = []) -> Literal[-1] | None: ...
85-
def loadNumpyAnnotations(self, data: _NDArray) -> list[_Annotation]: ...
86-
# def loadNumpyAnnotations(self, data: npt.NDArray[np.float64]) -> list[_Annotation]: ...
82+
def loadNumpyAnnotations(self, data: npt.NDArray[np.float64]) -> list[_Annotation]: ...
8783
@overload
8884
def annToRLE(self, ann: _AnnotationG[_RLE]) -> _RLE: ...
8985
@overload
9086
def annToRLE(self, ann: _AnnotationG[_EncodedRLE]) -> _EncodedRLE: ...
9187
@overload
9288
def annToRLE(self, ann: _AnnotationG[_TPolygonSegmentation]) -> _EncodedRLE: ...
93-
def annToMask(self, ann: _Annotation) -> _NDArray: ...
94-
# def annToMask(self, ann: _Annotation) -> npt.NDArray[np.uint8]: ...
89+
def annToMask(self, ann: _Annotation) -> npt.NDArray[np.uint8]: ...

stubs/pycocotools/pycocotools/cocoeval.pyi

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
from _typeshed import Incomplete
21
from typing import Literal, TypedDict
32
from typing_extensions import TypeAlias
43

5-
from .coco import COCO
4+
import numpy as np
5+
import numpy.typing as npt
66

7-
# TODO: Use numpy types when #5768 is resolved.
8-
# import numpy as np
9-
# import numpy.typing as npt
7+
from .coco import COCO
108

11-
_NDArray: TypeAlias = Incomplete
9+
_NDFloatArray: TypeAlias = npt.NDArray[np.float64]
1210
_TIOU: TypeAlias = Literal["segm", "bbox", "keypoints"]
1311

1412
class _ImageEvaluationResult(TypedDict):
@@ -18,58 +16,46 @@ class _ImageEvaluationResult(TypedDict):
1816
maxDet: int
1917
dtIds: list[int]
2018
gtIds: list[int]
21-
dtMatches: _NDArray
22-
# dtMatches: npt.NDArray[np.float64]
23-
gtMatches: _NDArray
24-
# gtMatches: npt.NDArray[np.float64]
19+
dtMatches: _NDFloatArray
20+
gtMatches: _NDFloatArray
2521
dtScores: list[float]
26-
gtIgnore: _NDArray
27-
# gtIgnore: npt.NDArray[np.float64]
28-
dtIgnore: _NDArray
29-
# dtIgnore: npt.NDArray[np.float64]
22+
gtIgnore: _NDFloatArray
23+
dtIgnore: _NDFloatArray
3024

3125
class _EvaluationResult(TypedDict):
3226
params: Params
3327
counts: list[int]
3428
date: str
35-
# precision: npt.NDArray[np.float64]
36-
precision: _NDArray
37-
# recall: npt.NDArray[np.float64]
38-
recall: _NDArray
39-
# scores: npt.NDArray[np.float64]
40-
scores: _NDArray
29+
precision: _NDFloatArray
30+
recall: _NDFloatArray
31+
scores: _NDFloatArray
4132

4233
class COCOeval:
4334
cocoGt: COCO
4435
cocoDt: COCO
4536
evalImgs: list[_ImageEvaluationResult]
4637
eval: _EvaluationResult
4738
params: Params
48-
stats: _NDArray
49-
# stats: npt.NDArray[np.float64]
39+
stats: _NDFloatArray
5040
ious: dict[tuple[int, int], list[float]]
5141
def __init__(self, cocoGt: COCO | None = None, cocoDt: COCO | None = None, iouType: _TIOU = "segm") -> None: ...
5242
def evaluate(self) -> None: ...
5343
def computeIoU(self, imgId: int, catId: int) -> list[float]: ...
54-
def computeOks(self, imgId: int, catId: int) -> _NDArray: ...
55-
# def computeOks(self, imgId: int, catId: int) -> npt.NDArray[np.float64]: ...
44+
def computeOks(self, imgId: int, catId: int) -> _NDFloatArray: ...
5645
def evaluateImg(self, imgId: int, catId: int, aRng: list[int], maxDet: int) -> _ImageEvaluationResult: ...
5746
def accumulate(self, p: Params | None = None) -> None: ...
5847
def summarize(self) -> None: ...
5948

6049
class Params:
6150
imgIds: list[int]
6251
catIds: list[int]
63-
iouThrs: _NDArray
64-
# iouThrs: npt.NDArray[np.float64]
65-
recThrs: _NDArray
66-
# recThrs: npt.NDArray[np.float64]
52+
iouThrs: _NDFloatArray
53+
recThrs: _NDFloatArray
6754
maxDets: list[int]
6855
areaRng: list[list[float]]
6956
areaRngLbl: list[str]
7057
useCats: int
71-
kpt_oks_sigmas: _NDArray
72-
# kpt_oks_sigmas: npt.NDArray[np.float64]
58+
kpt_oks_sigmas: _NDFloatArray
7359
iouType: _TIOU
7460
useSegm: int | None
7561
def __init__(self, iouType: _TIOU = "segm") -> None: ...

stubs/pycocotools/pycocotools/mask.pyi

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
from _typeshed import Incomplete
21
from typing import Any, overload
32
from typing_extensions import TypeAlias
43

5-
from . import _EncodedRLE
4+
import numpy as np
5+
import numpy.typing as npt
66

7-
# TODO: Use numpy types when #5768 is resolved.
8-
# import numpy as np
9-
# import numpy.typing as npt
7+
from . import _EncodedRLE
108

11-
_NPUInt32: TypeAlias = Incomplete # np.uint32
12-
_NDArrayUInt8: TypeAlias = Incomplete # npt.NDArray[np.uint8]
13-
_NDArrayUInt32: TypeAlias = Incomplete # npt.NDArray[np.uint32]
14-
_NDArrayFloat64: TypeAlias = Incomplete # npt.NDArray[np.float64]
9+
_NPUInt32: TypeAlias = np.uint32
10+
_NDArrayUInt8: TypeAlias = npt.NDArray[np.uint8]
11+
_NDArrayUInt32: TypeAlias = npt.NDArray[np.uint32]
12+
_NDArrayFloat64: TypeAlias = npt.NDArray[np.float64]
1513

1614
def iou(
1715
dt: _NDArrayUInt32 | list[float] | list[_EncodedRLE],

0 commit comments

Comments
 (0)