-
-
Notifications
You must be signed in to change notification settings - Fork 12k
Closed
Description
Describe the issue:
np.select no longer accepts default arrays in its type hint. This code still works as expected at runtime but fails during type checking.
I traced this regression to PR #30246 by checking blame logs. Numpy 2.3.3 was a working version.
Reproduce the code example:
import numpy as np
np.select(
condlist=[np.zeros((2, 2), dtype=np.bool_)],
choicelist=[np.ones((2, 2), dtype=np.int8)],
default=np.array([1, 0], dtype=np.int8), # Type error on working code
)Error message:
select.py:3: error: No overload variant of "select" matches argument types "list[ndarray[tuple[int, int], dtype[numpy.bool[builtins.bool]]]]", "list[ndarray[tuple[int, int], dtype[signedinteger[_8Bit]]]]", "ndarray[tuple[Any, ...], dtype[signedinteger[_8Bit]]]" [call-overload]
select.py:3: note: Possible overload variants:
select.py:3: note: def [_ArrayT: ndarray[tuple[Any, ...], dtype[Any]]] select(condlist: _SizedIterable[_SupportsArray[dtype[numpy.bool[builtins.bool]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]]]] | builtins.bool | _NestedSequence[builtins.bool]], choicelist: Sequence[_ArrayT], default: complex | str | bytes | generic[Any] = ...) -> _ArrayT
select.py:3: note: def [_ScalarT: generic[Any]] select(condlist: _SizedIterable[_SupportsArray[dtype[numpy.bool[builtins.bool]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]]]] | builtins.bool | _NestedSequence[builtins.bool]], choicelist: Sequence[_SupportsArray[dtype[_ScalarT]] | _NestedSequence[_SupportsArray[dtype[_ScalarT]]]] | ndarray[tuple[Any, ...], dtype[_ScalarT]], default: complex | str | bytes | generic[Any] = ...) -> ndarray[tuple[Any, ...], dtype[_ScalarT]]
select.py:3: note: def select(condlist: _SizedIterable[_SupportsArray[dtype[numpy.bool[builtins.bool]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]]]] | builtins.bool | _NestedSequence[builtins.bool]], choicelist: Sequence[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]], default: complex | str | bytes | generic[Any] = ...) -> ndarray[tuple[Any, ...], dtype[Any]]
Found 1 error in 1 file (checked 1 source file)Python and NumPy Versions:
NumPy: 2.4.0
Python: 3.13.2 (tags/v3.13.2:4f8bb39, Feb 4 2025, 15:23:48) [MSC v.1942 64 bit (AMD64)]
Type-checker version and settings:
mypy 1.19.1 (compiled: yes)
Command: mypy --strict select.py
Pylance also errors here.
Additional typing packages.
No response
jorenham