8000 TYP: Type ``MaskedArray.repeat``, improve overloads for ``NDArray.repeat``, ``generic.repeat``, and ``np.repeat`` by MarcoGorelli · Pull Request #28849 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: Type MaskedArray.repeat, improve overloads for NDArray.repeat, generic.repeat, and np.repeat #28849

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

Merged
merged 4 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

10000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
TYP: Type np.ma.repeat and MaskedArray.repeat
  • Loading branch information
MarcoGorelli committed Apr 28, 2025
commit 5e8f535c8f9b2e6b54f341f90c2fcdfedb6a06c2
23 changes: 21 additions & 2 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,13 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
copy: Any
diagonal: Any
flatten: Any
repeat: Any

def repeat(
self,
repeats: _ArrayLikeInt_co,
axis: SupportsIndex | None = ...,
) -> MaskedArray[_Shape, _DTypeT_co]: ...

squeeze: Any
swapaxes: Any
T: Any
Expand Down Expand Up @@ -996,7 +1002,20 @@ nonzero: _frommethod
prod: _frommethod
product: _frommethod
ravel: _frommethod
repeat: _frommethod

@overload
def repeat(
a: _ArrayLike[_ScalarT],
repeats: _ArrayLikeInt_co,
axis: SupportsIndex | None = ...,
) -> _MaskedArray[_ScalarT]: ...
@overload
def repeat(
a: ArrayLike,
repeats: _ArrayLikeInt_co,
axis: SupportsIndex | None = ...,
) -> _MaskedArray[Any]: ...

soften_mask: _frommethod
std: _frommethod
sum: _frommethod
Expand Down
9 changes: 9 additions & 0 deletions numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ assert_type(np.ma.filled([[1,2,3]]), NDArray[Any])
# https://github.com/numpy/numpy/pull/28742#discussion_r2048968375
assert_type(np.ma.filled(MAR_1d), np.ndarray[tuple[int], np.dtype]) # type: ignore[assert-type]

assert_type(MAR_b.repeat(3), MaskedNDArray[np.bool])
assert_type(MAR_2d_f4.repeat(MAR_i8), MaskedNDArray[np.float32])

assert_type(np.ma.repeat(b, 1), MaskedNDArray[np.bool])
assert_type(np.ma.repeat(f4, 1), MaskedNDArray[np.float32])
assert_type(np.ma.repeat(f, 1), MaskedNDArray[Any])
assert_type(np.ma.repeat(MAR_b, 1), MaskedNDArray[np.bool])
assert_type(np.ma.repeat(AR_f4, 1), MaskedNDArray[np.float32])

assert_type(np.ma.allequal(AR_f4, MAR_f4), bool)
assert_type(np.ma.allequal(AR_f4, MAR_f4, fill_value=False), bool)

Expand Down
Loading
0