Skip to content

TYP: False positives in ndarray.__setitem__ with object_ dtype in NumPy 2.2 #27964

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

Closed
jakevdp opened this issue Dec 10, 2024 · 2 comments · Fixed by #27967
Closed

TYP: False positives in ndarray.__setitem__ with object_ dtype in NumPy 2.2 #27964

jakevdp opened this issue Dec 10, 2024 · 2 comments · Fixed by #27967

Comments

@jakevdp
Copy link
Contributor

jakevdp commented Dec 10, 2024

Describe the issue:

Under NumPy 2.2, assignment of a slice to an object array results in a type check failure

Reproduce the code example:

import numpy as np
x = np.zeros(1, dtype=object)
x[0] = slice(None)

Error message:

tmp.py:3: error: No overload variant of "__setitem__" of "ndarray" matches argument types "int", "slice"  [call-overload]
tmp.py:3: note: Possible overload variants:
tmp.py:3: note:     def __setitem__(self, str | list[str], Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], /) -> None
tmp.py:3: note:     def __setitem__(self, SupportsIndex | slice | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | tuple[SupportsIndex | slice | EllipsisType | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[integer[Any]]]] | builtins.bool | int | _NestedSequence[builtins.bool | int] | None, ...] | None, Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], /) -> None
Found 1 error in 1 file (checked 1 source file)

Python and NumPy Versions:

>>> import sys, numpy; print(numpy.__version__); print(sys.version)
2.2.0
3.12.3 (v3.12.3:f6650f9ad7, Apr  9 2024, 08:18:47) [Clang 13.0.0 (clang-1300.0.29.30)]

Runtime Environment:

>>> import numpy; numpy.show_runtime()
[{'numpy_version': '2.2.0',
  'python': '3.12.3 (v3.12.3:f6650f9ad7, Apr  9 2024, 08:18:47) [Clang 13.0.0 '
            '(clang-1300.0.29.30)]',
  'uname': uname_result(system='Darwin', node='jmdg-macbookpro.roam.internal', release='23.6.0', version='Darwin Kernel Version 23.6.0: Thu Sep 12 23:35:29 PDT 2024; root:xnu-10063.141.1.701.1~1/RELEASE_ARM64_T6000', machine='arm64')},
 {'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
                      'found': ['ASIMDHP'],
                      'not_found': ['ASIMDFHM']}}]

Context for the issue:

Related to #27957; this is a reduction of an error we're seeing in the JAX CI under NumPy 2.2

@jorenham jorenham changed the title BUG: type checking error in NumPy 2.2 TYP: False positives in ndarray.__setitem__ with object_ dtype in NumPy 2.2 Dec 10, 2024
@jorenham
Copy link
Member

caused by #27755

@jorenham
Copy link
Member

jorenham commented Dec 10, 2024

The problem is that ndarray.__setitem__ currently only accepts numpy.typing.ArrayLike values, causing it to reject valid values like None for np.inexact dtypes, and object() in np.object_ dtypes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants