Skip to content

Conversation

@MarcoGorelli
Copy link
Member

MaskedArray.reshape only accepts *s and **kwargs as arguments. However, they get passed down as-is to ndarray.reshape:

numpy/numpy/ma/core.py

Lines 4821 to 4827 in 75e86ba

kwargs.update(order=kwargs.get('order', 'C'))
result = self._data.reshape(*s, **kwargs).view(type(self))
result._update_from(self)
mask = self._mask
if mask is not nomask:
result._mask = mask.reshape(*s, **kwargs)
return result

As noted in #29403, the kwargs update line has no effect. order is keyword-only

Given that order is keyword-only in ndarray.reshape, a call to MaskedArray.reshape is valid if and only if the same call to ndarray.reshape is.

So, I've copied over the overloads from ndarray.reshape

@jorenham jorenham added the component: numpy.ma masked arrays label Jul 21, 2025
@jorenham jorenham changed the title TYP: Type `MaskedArray.reshape TYP: Type MaskedArray.reshape Jul 21, 2025
Co-authored-by: Joren Hammudoglu <[email protected]>
@MarcoGorelli MarcoGorelli marked this pull request as ready for review July 22, 2025 07:46
@jorenham jorenham merged commit 8b2321d into numpy:main Jul 23, 2025
78 checks passed
@jorenham
Copy link
Member

Merci!

IndifferentArea pushed a commit to IndifferentArea/numpy that referenced this pull request Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants