You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FAILED array_api_tests/test_manipulation_functions.py::test_reshape - AttributeError: attribute 'shape' of 'numpy.generic' objects is not writable
========== FAILING CODE SNIPPET:
xp.reshape(False,(1,), **kw) with kw ={'copy': False}
====================
and
_________________________________ test_reshape _________________________________
[gw1] linux -- Python 3.13.14 /opt/hostedtoolcache/Python/3.13.14/x64/bin/python
+ Exception Group Traceback (most recent call last):
| File "/home/runner/work/array-api-compat/array-api-compat/array-api-tests/array_api_tests/test_manipulation_functions.py", line 428, in test_reshape
| @given(
|
| File "/opt/hostedtoolcache/Python/3.13.14/x64/lib/python3.13/site-packages/hypothesis/core.py", line 2297, in wrapped_test
| raise the_error_hypothesis_found
| ExceptionGroup: Hypothesis found 2 distinct failures. (2 sub-exceptions)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "/home/runner/work/array-api-compat/array-api-compat/array-api-tests/array_api_tests/test_manipulation_functions.py", line 436, in test_reshape
| out = xp.reshape(x, shape, **kw)
| File "/opt/hostedtoolcache/Python/3.13.14/x64/lib/python3.13/site-packages/array_api_compat/_internal.py", line 35, in wrapped_f
| return f(*args, xp=xp, **kwargs)
| File "/opt/hostedtoolcache/Python/3.13.14/x64/lib/python3.13/site-packages/array_api_compat/common/_aliases.py", line 461, in reshape
| y.shape = shape
| ^^^^^^^
| File "/opt/hostedtoolcache/Python/3.13.14/x64/lib/python3.13/site-packages/dask/utils.py", line 2061, in __set__
| raise AttributeError("Can't set attribute")
| AttributeError: Can't set attribute
|
| ========== FAILING CODE SNIPPET:
| xp.reshape(dask.array<zeros_like, shape=(0,), dtype=bool, chunksize=(0,), chunktype=numpy.ndarray>,(0,), **kw) with kw ={'copy': False}
| ====================
Both kinds of failures seem to be coming from the "classic" version which sets the attribute. It's probably easiest to skip the test for numpy <2 and dask.
So the problem is that numpy < 2 does not allow mutating the shape of scalars:
>>> pdb.runcall(xp.reshape, np.bool_(False), (1,), copy=False)
> /home/br/miniforge3/envs/np1.25/lib/python3.10/site-packages/array_api_compat/_internal.py(35)wrapped_f()
-> return f(*args, xp=xp, **kwargs)
(Pdb) s
--Call--
> /home/br/miniforge3/envs/np1.25/lib/python3.10/site-packages/array_api_compat/common/_aliases.py(448)reshape()
-> def reshape(
(Pdb) n
> /home/br/miniforge3/envs/np1.25/lib/python3.10/site-packages/array_api_compat/common/_aliases.py(457)reshape()
-> if copy is True:
(Pdb) n
> /home/br/miniforge3/envs/np1.25/lib/python3.10/site-packages/array_api_compat/common/_aliases.py(459)reshape()
-> elif copy is False:
(Pdb) n
> /home/br/miniforge3/envs/np1.25/lib/python3.10/site-packages/array_api_compat/common/_aliases.py(460)reshape()
-> y = x.view()
(Pdb) p type(x)
<class 'numpy.bool_'>
(Pdb) n
> /home/br/miniforge3/envs/np1.25/lib/python3.10/site-packages/array_api_compat/common/_aliases.py(461)reshape()
-> y.shape = shape
(Pdb) p type(y)
<class 'numpy.bool_'>
(Pdb) n
AttributeError: attribute 'shape' of 'numpy.generic' objects is not writable
> /home/br/miniforge3/envs/np1.25/lib/python3.10/site-packages/array_api_compat/common/_aliases.py(461)reshape()
Since (1) this works fine on numpy 2+, and (2) we will hopefully remove support for numpy < 2 in a foreseeable future, I think we can just add a skip and call it a day.
Activity
ev-br commentedon Jul 29, 2026
cc @stanbot8 for viz
ev-br commentedon Jul 29, 2026
So the problem is that
numpy < 2does not allow mutating the shape of scalars:Since (1) this works fine on numpy 2+, and (2) we will hopefully remove support for numpy < 2 in a foreseeable future, I think we can just add a skip and call it a day.
ev-br commentedon Jul 29, 2026
cf data-apis/array-api-compat#458 for a fix
ev-br commentedon Jul 29, 2026
Skips added in data-apis/array-api-compat#458, closing.