GeezerVison is showing github.com — TYP: Type ``MaskedArray.{trace,round,cumsum,cumprod}`` by MarcoGorelli · Pull Request #29307 · numpy/numpy
TYP: Type MaskedArray.{trace,round,cumsum,cumprod}
#29307
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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.pyi
(3)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -1741,6 +1741,7 @@ class _ArrayOrScalarCommon:
@overload
def argmin(self, /, axis: SupportsIndex | None = None, *, out: _BoolOrIntArrayT, keepdims: builtins.bool = False) -> _BoolOrIntArrayT: ...
# Keep in sync with `MaskedArray.round`
@overload # out=None (default)
def round(self, /, decimals: SupportsIndex = 0, out: None = None) -> Self: ...
@overload # out=ndarray
Expand Down
Expand Up
@@ -1776,13 +1777,15 @@ class _ArrayOrScalarCommon:
@overload
def compress(self, /, condition: _ArrayLikeInt_co, axis: SupportsIndex | None = None, *, out: _ArrayT) -> _ArrayT: ...
# Keep in sync with `MaskedArray.cumprod`
@overload # out: None (default)
def cumprod(self, /, axis: SupportsIndex | None = None, dtype: DTypeLike | None = None, out: None = None) -> NDArray[Any]: ...
@overload # out: ndarray
def cumprod(self, /, axis: SupportsIndex | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ...
@overload
def cumprod(self, /, axis: SupportsIndex | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...
# Keep in sync with `MaskedArray.cumsum`
@overload # out: None (default)
def cumsum(self, /, axis: SupportsIndex | None = None, dtype: DTypeLike | None = None, out: None = None) -> NDArray[Any]: ...
@overload # out: ndarray
Expand Down
Expand Up
@@ -2385,6 +2388,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
stable: bool | None = ...,
) -> None: ...
# Keep in sync with `MaskedArray.trace`
@overload
def trace(
self, # >= 2D array
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -46,6 +46,7 @@ from numpy import (
from numpy._globals import _NoValueType
from numpy._typing import (
ArrayLike,
DTypeLike,
NDArray,
_32Bit,
_64Bit,
Expand Down
Expand Up
@@ -1168,18 +1169,72 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
) -> _ArrayT: ...
def nonzero(self) -> tuple[_Array1D[intp], ...]: ...
def trace(self, offset=..., axis1=..., axis2=..., dtype=..., out=...): ...
# Keep in sync with `ndarray.trace`
@overload
def trace(
self, # >= 2D MaskedArray
offset: SupportsIndex = ...,
axis1: SupportsIndex = ...,
axis2: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: None = ...,
) -> Any: ...
@overload
def trace(
self, # >= 2D MaskedArray
offset: SupportsIndex = ...,
axis1: SupportsIndex = ...,
axis2: SupportsIndex = ...,
dtype: DTypeLike = ...,
*,
out: _ArrayT,
) -> _ArrayT: ...
@overload
def trace(
self, # >= 2D MaskedArray
offset: SupportsIndex,
axis1: SupportsIndex,
axis2: SupportsIndex,
dtype: DTypeLike,
out: _ArrayT,
) -> _ArrayT: ...
def dot(self, b, out=..., strict=...): ...
def sum(self, axis=..., dtype=..., out=..., keepdims=...): ...
def cumsum(self, axis=..., dtype=..., out=...): ...
# Keep in sync with `ndarray.cumsum`
@overload # out: None (default)
def cumsum(self, /, axis: SupportsIndex | None = None, dtype: DTypeLike | None = None, out: None = None) -> _MaskedArray[Any]: ...
@overload # out: ndarray
def cumsum(self, /, axis: SupportsIndex | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ...
@overload
def cumsum(self, /, axis: SupportsIndex | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...
def prod(self, axis=..., dtype=..., out=..., keepdims=...): ...
product: Any
def cumprod(self, axis=..., dtype=..., out=...): ...
# Keep in sync with `ndarray.cumprod`
@overload # out: None (default)
def cumprod(self, /, axis: SupportsIndex | None = None, dtype: DTypeLike | None = None, out: None = None) -> _MaskedArray[Any]: ...
@overload # out: ndarray
def cumprod(self, /, axis: SupportsIndex | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ...
@overload
def cumprod(self, /, axis: SupportsIndex | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...
def mean(self, axis=..., dtype=..., out=..., keepdims=...): ...
def anom(self, axis=..., dtype=...): ...
def var(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
def std(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
def round(self, decimals=..., out=...): ...
# Keep in sync with `ndarray.round`
@overload # out=None (default)
def round(self, /, decimals: SupportsIndex = 0, out: None = None) -> Self: ...
@overload # out=ndarray
def round(self, /, decimals: SupportsIndex, out: _ArrayT) -> _ArrayT: ...
@overload
def round(self, /, decimals: SupportsIndex = 0, *, out: _ArrayT) -> _ArrayT: ...
def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
# Keep in-sync with np.ma.argmin
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -383,6 +383,18 @@ assert_type(MAR_2d_f4.T, np.ma.MaskedArray[tuple[int, int], np.dtype[np.float32]
assert_type(MAR_2d_f4.nonzero(), tuple[_Array1D[np.intp], ...])
assert_type(MAR_2d_f4.nonzero()[0], _Array1D[np.intp])
assert_type(MAR_f8.trace(), Any)
assert_type(MAR_f8.trace(out=MAR_subclass), MaskedArraySubclass)
assert_type(MAR_f8.round(), MaskedArray[np.float64])
assert_type(MAR_f8.round(out=MAR_subclass), MaskedArraySubclass)
assert_type(MAR_f8.cumprod(), MaskedArray[Any])
assert_type(MAR_f8.cumprod(out=MAR_subclass), MaskedArraySubclass)
assert_type(MAR_f8.cumsum(), MaskedArray[Any])
assert_type(MAR_f8.cumsum(out=MAR_subclass), MaskedArraySubclass)
# Masked Array addition
assert_type(MAR_b + AR_LIKE_u, MaskedArray[np.uint32])
Expand Down
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.