Skip to content

Commit

Permalink
Merge pull request numpy#28053 from jorenham/typing/__setitem__-void
Browse files Browse the repository at this point in the history
TYP: fix ``void`` arrays not accepting ``str`` keys in ``__setitem__``
  • Loading branch information
charris authored Dec 22, 2024
2 parents 9aa5cda + f03994d commit 97c347e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,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 @@ -175,3 +175,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]

0 comments on commit 97c347e

Please sign in to comment.