Skip to content

BUG: reshape accept an empty array and copy=False - #232

Merged
ev-br merged 2 commits into
data-apis:mainfrom
stanbot8:fix/reshape-empty-view-no-copy
Jul 28, 2026
Merged

BUG: reshape accept an empty array and copy=False#232
ev-br merged 2 commits into
data-apis:mainfrom
stanbot8:fix/reshape-empty-view-no-copy

Conversation

@stanbot8

Copy link
Copy Markdown
Contributor

reshape with copy=False rejects an empty view.

Skip the shares_memory view test for an empty array, so reshape with copy=False returns the view.

Raise ValueError instead of AttributeError when a copy is necessary. The 2025.12 specification requires ValueError when copy=False needs a copy, and numpy raises the same type.

The failing reshape test in data-apis/array-api-tests#432 passes with this change.

All tests pass.

a = asarray(np.ones((2, 3)).T)
b = reshape(a, (3, 2), copy=True)
assert_raises(AttributeError, lambda: reshape(a, (2, 3), copy=False))
assert_raises(ValueError, lambda: reshape(a, (2, 3), copy=False))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, a back-compat break. That said, there is no reason for an AttributeError here, and the spec says ValueError, https://data-apis.org/array-api/2022.12/API_specification/generated/array_api.reshape.html

Comment thread array_api_strict/_manipulation_functions.py
@ev-br ev-br added this to the 2.7 milestone Jul 28, 2026

@ev-br ev-br left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @stanbot8

@ev-br
ev-br merged commit 4f60e61 into data-apis:main Jul 28, 2026
19 of 20 checks passed
@ev-br ev-br changed the title fix: accept an empty view without a copy BUG: reshape accept an empty array and copy=False Jul 28, 2026
@stanbot8
stanbot8 deleted the fix/reshape-empty-view-no-copy branch July 28, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants