Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1113ec1

Browse filesBrowse files
authored
Merge pull request #28055 from charris/backport-28053
TYP: fix ``void`` arrays not accepting ``str`` keys in ``__setitem__``
2 parents 52a763a + 06cb2aa commit 1113ec1
Copy full SHA for 1113ec1

File tree

2 files changed

+9
-0
lines changed
Filter options

2 files changed

+9
-0
lines changed

‎numpy/__init__.pyi

Copy file name to clipboardExpand all lines: numpy/__init__.pyi
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
21332133
value: _ConvertibleToDT64 | _NestedSequence[_ConvertibleToDT64],
21342134
/,
21352135
) -> None: ...
2136+
@overload # void
2137+
def __setitem__(self: NDArray[void], key: str | list[str], value: object, /) -> None: ...
21362138
@overload # catch-all
21372139
def __setitem__(self, key: _ToIndices, value: ArrayLike, /) -> None: ...
21382140

‎numpy/typing/tests/data/pass/ndarray_misc.py

Copy file name to clipboardExpand all lines: numpy/typing/tests/data/pass/ndarray_misc.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,10 @@ class SubClass(npt.NDArray[np.float64]): ...
174174
complex(np.array(1.0, dtype=np.float64))
175175

176176
operator.index(np.array(1, dtype=np.int64))
177+
178+
# this fails on numpy 2.2.1
179+
# https://github.com/scipy/scipy/blob/a755ee77ec47a64849abe42c349936475a6c2f24/scipy/io/arff/tests/test_arffread.py#L41-L44
180+
A_float = np.array([[1, 5], [2, 4], [np.nan, np.nan]])
181+
A_void: npt.NDArray[np.void] = np.empty(3, [("yop", float), ("yap", float)])
182+
A_void["yop"] = A_float[:, 0]
183+
A_void["yap"] = A_float[:, 1]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.