-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: add type annotations to numpy.ma
#26404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks @johnthagen. This is more of a feature request I think. All of diff --git a/numpy/ma/core.pyi b/numpy/ma/core.pyi
index d6cc0a782c..c3f27e1271 100644
--- a/numpy/ma/core.pyi
+++ b/numpy/ma/core.pyi
@@ -167,7 +167,7 @@ def __next__(self): ...
class MaskedArray(ndarray[_ShapeType, _DType_co]):
__array_priority__: Any
- def __new__(cls, data=..., mask=..., dtype=..., copy=..., subok=..., ndmin=..., fill_value=..., keep_mask=..., hard_mask=..., shrink=..., order=...): ...
+ def __new__(cls, data=..., mask=..., dtype=..., copy=..., subok=..., ndmin=..., fill_value=..., keep_mask=..., hard_mask=..., shrink=..., order=...) -> 'MaskedArray': ...
def __array_finalize__(self, obj): ...
def __array_wrap__(self, obj, context=..., return_scalar=...): ...
def view(self, dtype=..., type=..., fill_value=...): ...
@@ -358,7 +358,7 @@ def array(
shrink=...,
subok=...,
ndmin=...,
-): ...
+) -> MaskedArray: ...
def is_masked(x): ...
class _extrema_operation(_MaskedUFunc): But that whole I'll change this to an enhancement request. |
numpy.ma
numpy.ma
No problem! I was under the impression that all of Numpy fully supported static typing (and even includes its own Mypy plugin) so that it why I thought it was a bug report if some of the static typing was incorrect/missing. Regardless, thank you for the clear feedback and consideration. |
I think all namespaces should have entries for all public objects, and the main namespaces and most important other namespaces ( |
I'd be glad to help! I Just need some guidance or a checklist. Is it literally all the functions and methods in |
Pretty much, yes. Also the other I'd suggest picking a small, representative subset and typing those. Once the review on those is done, that establishes the patterns to expand to the full set of functions/objects. E.g.:
|
And use the type annotations for the functions in the main namespace, as well as the |
Typing
|
#26081 implements |
Describe the issue:
Running Mypy on some functions within
numpy.ma
lead to type checking errors due to missing annotations.Reproduce the code example:
Error message:
Python and NumPy Versions:
Runtime Environment:
Context for the issue:
We rely on type checking to find bugs in our software that uses Numpy before it is executed. This enables higher code quality and reliability. False positive type errors cost time to track down and can distract from real issues.
Type annotations also help IDEs such as PyCharm and VS Code perform better intellisense during development.
The text was updated successfully, but these errors were encountered: