Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
98264cb
[DEP] Deprecate setting the shape attribute of a numpy array
eendebakpt Jul 31, 2025
27ef5f2
add release note
eendebakpt Jul 31, 2025
b7842a8
update tests
eendebakpt Jul 31, 2025
9af1e83
more conversions
eendebakpt Jul 31, 2025
1695917
convert more tests
eendebakpt Aug 6, 2025
1d71fc5
ma
eendebakpt Aug 6, 2025
e8cbd57
fix generator and mrecords
eendebakpt Aug 6, 2025
354a04e
review comments
eendebakpt Aug 6, 2025
bea4884
remove debugging code
eendebakpt Aug 6, 2025
5c8a65e
remove examples
eendebakpt Aug 7, 2025
914462d
restore examples wiht only get of shape
eendebakpt Aug 7, 2025
7e06ce2
remove doc with deprecated shape setting
eendebakpt Aug 7, 2025
2e80bf0
update release note
eendebakpt Aug 7, 2025
d49ab1e
warn for all subclasses of ndarray
eendebakpt Aug 10, 2025
37d1b42
convert one more shape set
eendebakpt Aug 10, 2025
b888253
add deprecation test
eendebakpt Aug 10, 2025
5576aa2
Update numpy/_core/tests/test_umath.py
eendebakpt Aug 15, 2025
5de80b9
review comments
eendebakpt Aug 15, 2025
0ff8bb0
Merge branch 'deprecate_shape_v3' of github.com:eendebakpt/numpy into…
eendebakpt Aug 15, 2025
f096794
Apply suggestions from code review
eendebakpt Aug 24, 2025
1a237cf
Merge branch 'main' into deprecate_shape_v3
eendebakpt Aug 24, 2025
198e62a
Merge branch 'main' into deprecate_shape_v3
eendebakpt Aug 27, 2025
f739d54
review comments
eendebakpt Aug 28, 2025
87a45e7
Merge branch 'main' into deprecate_shape_v3
eendebakpt Sep 4, 2025
e51276d
Merge branch 'main' into deprecate_shape_v3
eendebakpt Sep 25, 2025
f45274e
review comments
eendebakpt Oct 19, 2025
96e029b
update pr number
eendebakpt Oct 22, 2025
48cdec4
Merge branch 'main' into deprecate_shape_v3
eendebakpt Dec 15, 2025
9482110
Merge branch 'main' into deprecate_shape_v3
eendebakpt Jan 2, 2026
2ed9a48
Merge branch 'deprecate_shape_v3' of github.com:eendebakpt/numpy into…
eendebakpt Jan 2, 2026
bfed477
Update numpy/_core/src/multiarray/getset.c
seberg Jan 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review comments
  • Loading branch information
eendebakpt committed Aug 28, 2025
commit f739d546fd61978bbf94edc0c46a0a8d4c6b9ec2
3 changes: 2 additions & 1 deletion 3 doc/release/upcoming_changes/29492.deprecation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ threads. As an alternative, you can create a new view via
`np.reshape` or `np.ndarray.reshape`. For example: ``x = np.arange(15); x = np.reshape(x, (3, 5))``.
To ensure no copy is made from the data, one can use ``np.reshape(..., copy = False)``.
Comment thread
eendebakpt marked this conversation as resolved.
Outdated

Directly setting the shape on an array is possible with the private method `np.ndarray._set_shape`.
Directly setting the shape on an array is discouraged, but possible with the
Comment thread
eendebakpt marked this conversation as resolved.
Outdated
private method `np.ndarray._set_shape`.

2 changes: 1 addition & 1 deletion 2 numpy/_core/src/multiarray/getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ array_shape_set(PyArrayObject *self, PyObject *val, void* NPY_UNUSED(ignored))
/* Deprecated NumPy 2.4, 2025-07-29 */
if (DEPRECATE("Setting the shape on a NumPy array has been deprecated"
" in NumPy 2.4.\nAs an alternative, you can create a new"
" view using np.reshape."
" view using np.reshape (with copy=False if needed)."
) < 0 ) {
return -1;
}
Expand Down
8 changes: 2 additions & 6 deletions 8 numpy/_core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -4818,18 +4818,14 @@ class BadArr1(np.ndarray):
def __array_finalize__(self, obj):
# The outer call reshapes to 3 dims, try to do a bad reshape.
if self.ndim == 3:
with warnings.catch_warnings(): # gh-28901
warnings.filterwarnings('ignore', category=DeprecationWarning)
self.shape = self.shape + (1,)
self._set_shape(self.shape + (1,))

class BadArr2(np.ndarray):
def __array_finalize__(self, obj):
if isinstance(obj, BadArr2):
# outer inserts 1-sized dims. In that case disturb them.
if self.shape[-1] == 1:
with warnings.catch_warnings(): # gh-28901
warnings.filterwarnings('ignore', category=DeprecationWarning)
self.shape = self.shape[::-1]
self._set_shape(self.shape[::-1])

for cls in [BadArr1, BadArr2]:
arr = np.ones((2, 3)).view(cls)
Expand Down
3 changes: 1 addition & 2 deletions 3 numpy/linalg/_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ def tensorsolve(a, b, axes=None):
a = a.reshape(prod, prod)
b = b.ravel()
res = wrap(solve(a, b))
res = res.reshape(oldshape)
return res
return res.reshape(oldshape)


def _solve_dispatcher(a, b):
Expand Down
12 changes: 5 additions & 7 deletions 12 numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,7 @@ def reduce(self, target, axis=0, dtype=None):
if t.shape == ():
t = t.reshape(1)
if m is not nomask:
m = make_mask(m, copy=True)
m = m.reshape((1,))
m = make_mask(m, copy=True).reshape((1,))

if m is nomask:
tr = self.f.reduce(t, axis)
Expand Down Expand Up @@ -2726,8 +2725,7 @@ def __getitem__(self, indx):
_mask = self.maskiter.__getitem__(indx)
if isinstance(_mask, ndarray):
# set shape to match that of data; this is needed for matrices
_mask = _mask.reshape(result.shape)
result._mask = _mask
result._mask = _mask.reshape(result.shape)
elif isinstance(_mask, np.void):
return mvoid(result, mask=_mask, hardmask=self.ma._hardmask)
elif _mask: # Just a scalar, masked
Expand Down Expand Up @@ -4793,9 +4791,9 @@ def reshape(self, *s, **kwargs):

Notes
-----
The reshaping operation cannot guarantee that a copy will not be made,
to modify the shape in place, use ``a.shape = s``. Note: reshaping in
place is deprecated.
By default, the reshaping operation will make a copy if a view
with different strides is not possible. To ensure a view,
pass ``copy=False``.

Examples
--------
Expand Down
3 changes: 1 addition & 2 deletions 3 numpy/random/_generator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3952,8 +3952,7 @@ cdef class Generator:
_factor = u * np.sqrt(s)

x = mean + x @ _factor.T
x = x.reshape(tuple(final_shape))
return x
return x.reshape(tuple(final_shape))

def multinomial(self, object n, object pvals, size=None):
"""
Expand Down
3 changes: 1 addition & 2 deletions 3 numpy/random/mtrand.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4265,8 +4265,7 @@ cdef class RandomState:

x = np.dot(x, np.sqrt(s)[:, None] * v)
x += mean
x = x.reshape(tuple(final_shape))
return x
return x.reshape(tuple(final_shape))

def multinomial(self, long n, object pvals, size=None):
"""
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.