Skip to content

Commit 1113ec1

Browse 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

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

numpy/__init__.pyi

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy