8000 TYP: fix ``void`` arrays not accepting ``str`` keys in ``__setitem__`` by charris · Pull Request #28055 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: fix void arrays not accepting str keys in __setitem__ #28055

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 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
value: _ConvertibleToDT64 | _NestedSequence[_ConvertibleToDT64],
/,
) -> None: ...
@overload # void
def __setitem__(self: NDArray[void], key: str | list[str], value: object, /) -> None: ...
@overload # catch-all
def __setitem__(self, key: _ToIndices, value: ArrayLike, /) -> None: ...

Expand Down
7 changes: 7 additions & 0 deletions numpy/typing/tests/data/pass/ndarray_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,10 @@ class SubClass(npt.NDArray[np.float64]): ...
complex(np.array(1.0, dtype=np.float64))

operator.index(np.array(1, dtype=np.int64))

# this fails on numpy 2.2.1
# https://github.com/scipy/scipy/blob/a755ee77ec47a64849abe42c349936475a6c2f24/scipy/io/arff/tests/test_arffread.py#L41-L44
A_float = np.array([[1, 5], [2, 4], [np.nan, np.nan]])
A_void: npt.NDArray[np.void] = np.empty(3, [("yop", float), ("yap", float)])
A_void["yop"] = A_float[:, 0]
A_void["yap"] = A_float[:, 1]
Loading
0