Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6c86000
👽️ `ma.core.arange` sync with upstream
jorenham Dec 23, 2025
2293410
👽️ `ma.core.clip` sync with upstream
jorenham Dec 23, 2025
f837399
👽️ `ma.core.empty` sync with upstream
jorenham Dec 23, 2025
9c43694
👽️ `ma.core.empty_like` sync with upstream
jorenham Dec 23, 2025
eb01197
👽️ `ma.core.{zeros,ones}[_like]` sync with upstream
jorenham Dec 23, 2025
0e11a2d
👽️ `ma.core.frombuffer` sync ith upstream
jorenham Dec 23, 2025
7d5b583
👽️ `ma.core.fromfunction` sync with upstream
jorenham Dec 23, 2025
925c95a
👽️ `ma.core.identity` sync with upstream
jorenham Dec 23, 2025
cd2e4b6
👽️ `ma.core.indices` sync with upstream
jorenham Dec 23, 2025
4012b8b
👽️ `ma.core.squeeze` sync with upstream
jorenham Dec 23, 2025
f799f45
👽️ `ma.core._convert2ma` sync with upstream
jorenham Dec 23, 2025
442f9b4
👽️ `ma.core.{harden,soften,shrink}_mask` sync with upstream
jorenham Dec 23, 2025
7e39090
👽️ `ma.core.ids` sync with upstream
jorenham Dec 23, 2025
797d3df
👽️ `ma.core.nonzero` sync with upstream
jorenham Dec 23, 2025
6376b4f
👽️ `ma.core.ravel` sync with upstream
jorenham Dec 23, 2025
6a3ddc6
👽️ `ma.core.copy` sync with upstream
jorenham Dec 23, 2025
aae188c
👽️ `ma.core.diagonal` sync with upstream
jorenham Dec 23, 2025
d655469
👽️ `ma.core.repeat` sync with upstream
jorenham Dec 23, 2025
759e810
👽️ `ma.core.swapaxes` sync with upstream
jorenham Dec 23, 2025
146f2a8
👽️ `ma.core.anom[alies]` sync with upstream
jorenham Dec 23, 2025
f42d4f4
👽️ `ma.core.{all,any}` sync with upstream
jorenham Dec 23, 2025
e734e8e
👽️ `ma.core.compress` sync with upstream
jorenham Dec 23, 2025
464519c
👽️ `ma.core.cum{sum,prod}` sync with upstream
jorenham Dec 23, 2025
2b3ff25
👽️ `ma.core.{mean,sum,prod[uct]}` sync with upstream
jorenham Dec 23, 2025
abf76d8
👽️ `ma.core.trace` sync with upstream
jorenham Dec 23, 2025
64e6c9c
👽️ `ma.core.{std,var}` sync with upstream
jorenham Dec 23, 2025
b1d46f6
👽️ `ma.core.count` sync with upstream
jorenham Dec 23, 2025
ec07703
👽️ `ma.core.arg{min,max}` sync with upstream
jorenham Dec 23, 2025
993e643
👽️ `ma.core.as[any]array` sync with upstream
jorenham Dec 23, 2025
40e8878
👽️ `ma.core._frommethod` sync with upstream
jorenham Dec 23, 2025
47dbade
👽️ `numpy.ma.mrecords.fromtextfile` sync with upstream
jorenham Dec 23, 2025
23fd1f0
✅ update `ndarray.nonzero` test
jorenham Dec 23, 2025
ece5579
✅ actually run the runtime tests for `ma.recfunctions`
jorenham Dec 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/numpy-stubs/@test/runtime/legacy/recfunctions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""These tests are based on the doctests from `numpy/lib/recfunctions.py`."""

from collections.abc import Callable
from typing import TYPE_CHECKING, Any, assert_type

import numpy as np
Expand All @@ -11,6 +12,11 @@
# ruff: noqa: S101


def _test(fn: Callable[[], None]) -> None:
fn()


@_test
def test_recursive_fill_fields() -> None:
a: _nt.Array[np.void] = np.array(
[(1, 10.0), (2, 20.0)], dtype=[("A", np.int64), ("B", np.float64)]
Expand All @@ -20,6 +26,7 @@ def test_recursive_fill_fields() -> None:
assert_type(out, "_nt.Array1D[np.void]")


@_test
def test_get_names() -> None:
names: tuple[str | Any, ...]
names = rfn.get_names(np.empty((1,), dtype=[("A", int)]).dtype)
Expand All @@ -30,6 +37,7 @@ def test_get_names() -> None:
assert names


@_test
def test_get_names_flat() -> None:
names: tuple[str, ...]
names = rfn.get_names_flat(np.empty((1,), dtype=[("A", int)]).dtype)
Expand All @@ -40,11 +48,13 @@ def test_get_names_flat() -> None:
assert names


@_test
def test_flatten_descr() -> None:
ndtype = np.dtype([("a", "<i4"), ("b", [("b_a", "<f8"), ("b_b", "<i4")])])
assert_type(rfn.flatten_descr(ndtype), tuple[tuple[str, np.dtype]])


@_test
def test_get_fieldstructure() -> None:
ndtype = np.dtype([
("A", int),
Expand All @@ -53,13 +63,15 @@ def test_get_fieldstructure() -> None:
assert_type(rfn.get_fieldstructure(ndtype), dict[str, list[str]])


@_test
def test_merge_arrays() -> None:
assert_type(
rfn.merge_arrays((np.ones(((2),), np.int_), np.ones(((3),), np.float64))),
"np.recarray[_nt.Rank1, np.dtype[np.void]]",
)


@_test
def test_drop_fields() -> None:
ndtype = [("a", np.int64), ("b", [("b_a", np.double), ("b_b", np.int64)])]
a = np.ones(((3),), dtype=ndtype)
Expand All @@ -74,13 +86,15 @@ def test_drop_fields() -> None:
)


@_test
def test_rename_fields() -> None:
ndtype = [("a", np.int64), ("b", [("b_a", np.double), ("b_b", np.int64)])]
a = np.ones(((3),), dtype=ndtype)

assert_type(rfn.rename_fields(a, {"a": "A", "b_b": "B_B"}), "_nt.Array1D[np.void]")


@_test
def test_repack_fields() -> None:
dt: np.dtype[np.void] = np.dtype("u1, <i8, <f8", align=True)

Expand All @@ -89,34 +103,40 @@ def test_repack_fields() -> None:
assert_type(rfn.repack_fields(np.ones((3,), dtype=dt)), "_nt.Array1D[np.void]")


@_test
def test_structured_to_unstructured() -> None:
a = np.zeros(4, dtype=[("a", "i4"), ("b", "f4,u2"), ("c", "f4", 2)])
assert_type(rfn.structured_to_unstructured(a), "_nt.Array")


@_test
def unstructured_to_structured() -> None:
dt: np.dtype[np.void] = np.dtype([("a", "i4"), ("b", "f4,u2"), ("c", "f4", 2)])
a = np.arange(20, dtype=np.int32).reshape((4, 5))
assert_type(rfn.unstructured_to_structured(a, dt), "_nt.Array[np.void]")


@_test
def test_apply_along_fields() -> None:
b = np.ones(4, dtype=[("x", "i4"), ("y", "f4"), ("z", "f8")])
assert_type(rfn.apply_along_fields(np.mean, b), "_nt.Array1D[np.void]")


@_test
def test_assign_fields_by_name() -> None:
b = np.ones(4, dtype=[("x", "i4"), ("y", "f4"), ("z", "f8")])
assert_type(rfn.apply_along_fields(np.mean, b), "_nt.Array1D[np.void]")


@_test
def test_require_fields() -> None:
a = np.ones(4, dtype=[("a", "i4"), ("b", "f8"), ("c", "u1")])
assert_type(
rfn.require_fields(a, [("b", "f4"), ("c", "u1")]), "_nt.Array1D[np.void]"
)


@_test
def test_stack_arrays() -> None:
x = np.zeros(((2),), np.int32)
assert_type(rfn.stack_arrays(x), "_nt.Array1D[np.int32]")
Expand All @@ -126,10 +146,11 @@ def test_stack_arrays() -> None:
assert_type(rfn.stack_arrays((z, zz)), "_nt.MArray[np.void]")


@_test
def test_find_duplicates() -> None:
ndtype = np.dtype([("a", int)])

a = np.ma.ones(7, mask=[0, 0, 1, 0, 0, 0, 1]).view(ndtype)
a = np.ma.ones(7).view(ndtype)
assert_type(rfn.find_duplicates(a), "_nt.MArray[np.void, Any]")
assert_type(
rfn.find_duplicates(a, ignoremask=True, return_index=True),
Expand Down
2 changes: 1 addition & 1 deletion src/numpy-stubs/@test/static/accept/ndarray_misc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ assert_type(AR_f8.dot(1), _nt.Array[Any])
assert_type(AR_f8.dot([1]), Any)
assert_type(AR_f8.dot(1, out=AR_O_sub), SubArray)

assert_type(AR_f8.nonzero(), tuple[_nt.Array[np.intp], ...])
assert_type(AR_f8.nonzero(), tuple[_nt.Array1D[np.intp], ...])

assert_type(AR_f8.searchsorted(1), np.intp)
assert_type(AR_f8.searchsorted([1]), _nt.Array[np.intp])
Expand Down
2 changes: 1 addition & 1 deletion src/numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
def dot(self, b: ArrayLike, /, out: _ArrayT) -> _ArrayT: ...

# `nonzero()` is deprecated for 0d arrays/generics
def nonzero(self) -> tuple[_nt.Array[intp], ...]: ...
def nonzero(self) -> tuple[_nt.Array1D[intp], ...]: ...

#
@overload
Expand Down
5 changes: 3 additions & 2 deletions src/numpy-stubs/_core/fromnumeric.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,14 @@ def reshape(
a: ArrayLike, /, shape: Sequence[CanIndex], order: _OrderACF = "C", *, copy: bool | None = None
) -> _nt.Array[Incomplete]: ...

#
# keep in sync with `ma.core.swapaxes`
@overload
def swapaxes(a: _nt._ToArray_nd[_ScalarT], axis1: CanIndex, axis2: CanIndex) -> _nt.Array[_ScalarT]: ...
@overload
def swapaxes(a: ArrayLike, axis1: CanIndex, axis2: CanIndex) -> _nt.Array[Incomplete]: ...

#
# TODO: port shape-typing improvements from upstream
# keep in sync with `ma.core.repeat`
@overload
def repeat(
a: _nt._ToArray_nd[_ScalarT], repeats: _nt.CoInteger_nd, axis: CanIndex | None = None
Expand Down
2 changes: 1 addition & 1 deletion src/numpy-stubs/_core/numeric.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ def indices(dimensions: _nt.ToInteger_1d, dtype: DTypeLike, sparse: L[True]) ->
@overload
def indices(dimensions: _nt.ToInteger_1d, dtype: DTypeLike = ..., *, sparse: L[True]) -> tuple[_nt.Array, ...]: ...

#
# keep in sync with `ma.core.fromfunction`
def fromfunction(
function: Callable[..., _T],
shape: Sequence[int],
Expand Down
Loading