Repository: numpy/numtype
Pull request #281: 🏷️ stub `numpy.ma.testutils`
Author: login: jorenham
Labels: name: stubs: Incomplete
name: numpy.ma.*
Created: 2025-03-08T14:30:06Z | Merged: 2025-03-08T14:44:59Z

closes #37

Linked issue #37: Stubs missing for `numpy.ma.testutils` and `numpy.ma.timer_comparison`
- [x] `testutils` - #281
- [x] `timer_comparison` - #278

Diff:
diff --git a/src/numpy-stubs/ma/testutils.pyi b/src/numpy-stubs/ma/testutils.pyi
new file mode 100644
index 00000000..f211ef92
--- /dev/null
+++ b/src/numpy-stubs/ma/testutils.pyi
@@ -0,0 +1,71 @@
+from unittest import TestCase as _TestCase
+
+import numpy as np
+import numpy.typing as npt
+from numpy.testing import assert_, assert_allclose, assert_array_almost_equal_nulp, assert_raises
+from numpy.testing._private.utils import _ComparisonFunc
+
+__all__ = [
+    "TestCase",
+    "almost",
+    "approx",
+    "assert_",
+    "assert_allclose",
+    "assert_almost_equal",
+    "assert_array_almost_equal",
+    "assert_array_almost_equal_nulp",
+    "assert_array_approx_equal",
+    "assert_array_compare",
+    "assert_array_equal",
+    "assert_array_less",
+    "assert_close",
+    "assert_equal",
+    "assert_equal_records",
+    "assert_mask_equal",
+    "assert_not_equal",
+    "assert_raises",
+    "fail_if_array_equal",
+]
+
+def approx(
+    a: object,
+    b: object,
+    fill_value: bool = True,
+    rtol: float = 1e-5,
+    atol: float = 1e-8,
+) -> np.ndarray[tuple[int], np.dtype[np.bool]]: ...
+def almost(
+    a: object,
+    b: object,
+    decimal: int = 6,
+    fill_value: bool = True,
+) -> np.ndarray[tuple[int], np.dtype[np.bool]]: ...
+
+#
+def assert_equal_records(a: npt.NDArray[np.void], b: npt.NDArray[np.void]) -> None: ...
+def assert_equal(actual: object, desired: object, err_msg: str = "") -> None: ...
+def fail_if_equal(actual: object, desired: object, err_msg: str = "") -> None: ...
+def assert_almost_equal(actual: object, desired: object, decimal: int = 7, err_msg: str = "", verbose: bool = True) -> None: ...
+
+#
+def assert_array_compare(
+    comparison: _ComparisonFunc,
+    x: object,
+    y: object,
+    err_msg: str = "",
+    verbose: bool = True,
+    header: str = "",
+    fill_value: bool = True,
+) -> None: ...
+def assert_array_equal(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def fail_if_array_equal(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_approx_equal(x: object, y: object, decimal: int = 6, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_almost_equal(x: object, y: object, decimal: int = 6, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_less(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_mask_equal(m1: object, m2: object, err_msg: str = "") -> None: ...
+
+assert_not_equal = fail_if_equal
+assert_close = assert_almost_equal
+
+class TestCase(_TestCase):
+    def __init_subclass__(cls, *args: object, **kwargs: object) -> None: ...
diff --git a/tool/.mypyignore-todo.txt b/tool/.mypyignore-todo.txt
index f21dd39e..be6dcb97 100644
--- a/tool/.mypyignore-todo.txt
+++ b/tool/.mypyignore-todo.txt
@@ -20,5 +20,3 @@ numpy.f2py.diagnose
 numpy.f2py.crackfortran
 numpy.f2py.symbolic
 numpy.f2py.((cb|common|f90mod|use)_)?rules
-
-numpy.ma.testutils


Reviews:
user: login: guan404ming
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-08T14:42:39Z
user: login: jorenham
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-08T14:43:37Z

Review comments:
diff_hunk: @@ -0,0 +1,68 @@
+from unittest import TestCase
+
+import numpy as np
+import numpy.typing as npt
+from numpy.testing import assert_, assert_allclose, assert_array_almost_equal_nulp, assert_raises
+from numpy.testing._private.utils import _ComparisonFunc
+
+__all__ = [
+    "TestCase",
+    "almost",
+    "approx",
+    "assert_",
+    "assert_allclose",
+    "assert_almost_equal",
+    "assert_array_almost_equal",
+    "assert_array_almost_equal_nulp",
+    "assert_array_approx_equal",
+    "assert_array_compare",
+    "assert_array_equal",
+    "assert_array_less",
+    "assert_close",
+    "assert_equal",
+    "assert_equal_records",
+    "assert_mask_equal",
+    "assert_not_equal",
+    "assert_raises",
+    "fail_if_array_equal",
+]
+
+def approx(
+    a: object,
+    b: object,
+    fill_value: bool = True,
+    rtol: float = 1e-5,
+    atol: float = 1e-8,
+) -> np.ndarray[tuple[int], np.dtype[np.bool]]: ...
+def almost(
+    a: object,
+    b: object,
+    decimal: int = 6,
+    fill_value: bool = True,
+) -> np.ndarray[tuple[int], np.dtype[np.bool]]: ...
+
+#
+def assert_equal_records(a: npt.NDArray[np.void], b: npt.NDArray[np.void]) -> None: ...
+def assert_equal(actual: object, desired: object, err_msg: str = "") -> None: ...
+def fail_if_equal(actual: object, desired: object, err_msg: str = "") -> None: ...
+def assert_almost_equal(actual: object, desired: object, decimal: int = 7, err_msg: str = "", verbose: bool = True) -> None: ...
+
+#
+def assert_array_compare(
+    comparison: _ComparisonFunc,
+    x: object,
+    y: object,
+    err_msg: str = "",
+    verbose: bool = True,
+    header: str = "",
+    fill_value: bool = True,
+) -> None: ...
+def assert_array_equal(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def fail_if_array_equal(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_approx_equal(x: object, y: object, decimal: int = 6, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_almost_equal(x: object, y: object, decimal: int = 6, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_less(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_mask_equal(m1: object, m2: object, err_msg: str = "") -> None: ...
+
+assert_not_equal = fail_if_equal
path: src/numpy-stubs/ma/testutils.pyi
user: login: guan404ming
body: shall we add 

```
class TestCase(_TestCase):
    def __init_subclass__(cls, *args: Any, **kwargs: Any) -> None: ...
```

like #282 ?
created_at: 2025-03-08T14:40:14Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,68 @@
+from unittest import TestCase
+
+import numpy as np
+import numpy.typing as npt
+from numpy.testing import assert_, assert_allclose, assert_array_almost_equal_nulp, assert_raises
+from numpy.testing._private.utils import _ComparisonFunc
+
+__all__ = [
+    "TestCase",
+    "almost",
+    "approx",
+    "assert_",
+    "assert_allclose",
+    "assert_almost_equal",
+    "assert_array_almost_equal",
+    "assert_array_almost_equal_nulp",
+    "assert_array_approx_equal",
+    "assert_array_compare",
+    "assert_array_equal",
+    "assert_array_less",
+    "assert_close",
+    "assert_equal",
+    "assert_equal_records",
+    "assert_mask_equal",
+    "assert_not_equal",
+    "assert_raises",
+    "fail_if_array_equal",
+]
+
+def approx(
+    a: object,
+    b: object,
+    fill_value: bool = True,
+    rtol: float = 1e-5,
+    atol: float = 1e-8,
+) -> np.ndarray[tuple[int], np.dtype[np.bool]]: ...
+def almost(
+    a: object,
+    b: object,
+    decimal: int = 6,
+    fill_value: bool = True,
+) -> np.ndarray[tuple[int], np.dtype[np.bool]]: ...
+
+#
+def assert_equal_records(a: npt.NDArray[np.void], b: npt.NDArray[np.void]) -> None: ...
+def assert_equal(actual: object, desired: object, err_msg: str = "") -> None: ...
+def fail_if_equal(actual: object, desired: object, err_msg: str = "") -> None: ...
+def assert_almost_equal(actual: object, desired: object, decimal: int = 7, err_msg: str = "", verbose: bool = True) -> None: ...
+
+#
+def assert_array_compare(
+    comparison: _ComparisonFunc,
+    x: object,
+    y: object,
+    err_msg: str = "",
+    verbose: bool = True,
+    header: str = "",
+    fill_value: bool = True,
+) -> None: ...
+def assert_array_equal(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def fail_if_array_equal(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_approx_equal(x: object, y: object, decimal: int = 6, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_almost_equal(x: object, y: object, decimal: int = 6, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_array_less(x: object, y: object, err_msg: str = "", verbose: bool = True) -> None: ...
+def assert_mask_equal(m1: object, m2: object, err_msg: str = "") -> None: ...
+
+assert_not_equal = fail_if_equal
path: src/numpy-stubs/ma/testutils.pyi
user: login: jorenham
body: [`3f7b3f5` (#281)](https://github.com/numpy/numtype/pull/281/commits/3f7b3f5123aa7f28f156f68a1827b4dfe7b37406) 👌🏻 
created_at: 2025-03-08T14:43:37Z
author_association: MEMBER

PR comments:
user: login: jorenham
created_at: 2025-03-08T14:36:24Z
body: > Use this PR~~

It doesn't matter too much I suppose, so sure 🤷🏻. 

And since you also looked at it, care to review?
author_association: MEMBER
user: login: guan404ming
created_at: 2025-03-08T14:38:14Z
body: I accidentally deleted the comment, and I'm happy to help review!
author_association: MEMBER
user: login: guan404ming
created_at: 2025-03-08T14:43:00Z
body: LGTM~
author_association: MEMBER