Skip to content

test_reshape fails with copy= and numpy < 2 #446

Closed

Description

@ev-br

Caught several failures at

https://github.com/data-apis/array-api-compat/actions/runs/30433019201/job/90514326589?pr=394

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.

Activity

  1. ev-br commented on Jul 29, 2026

    @ev-br
    MemberAuthor

    cc @stanbot8 for viz

  2. ev-br commented on Jul 29, 2026

    @ev-br
    MemberAuthor

    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.

  3. ev-br commented on Jul 29, 2026

    @ev-br
    MemberAuthor
  4. ev-br commented on Jul 29, 2026

    @ev-br
    MemberAuthor

    Skips added in data-apis/array-api-compat#458, closing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions