GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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.

Sign up for GitHub

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

Merged
jorenham merged 3 commits into numpy:main from MarcoGorelli:ma-trace
Jul 2, 2025
+75 −4
Merged

TYP: Type MaskedArray.{trace,round,cumsum,cumprod} #29307

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
830d1ec
TYP: Type ``MaskedArray.{trace,round,cumsum,cumprod}``
MarcoGorelli Jun 26, 2025
20e04cf
sync comments
MarcoGorelli Jul 2, 2025
b41c566
redundant overload
MarcoGorelli Jul 2, 2025
File filter
Filter by extension

Clear filters
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
Diff view

There are no files selected for viewing

4 changes: 4 additions & 0 deletions 4 numpy/__init__.pyi
Show comments
View file
Open in desktop
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
63 changes: 59 additions & 4 deletions 63 numpy/ma/core.pyi
Show comments
View file
Open in desktop
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
12 changes: 12 additions & 0 deletions 12 numpy/typing/tests/data/reveal/ma.pyi
Show comments
View file
Open in desktop
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.