Skip to content

Commit e351c3a

Browse files
authored
Merge pull request #137 from IntelPython/align-with-numpy-2.5
Align with numpy 2.5
2 parents 0b4ed7e + aee582c commit e351c3a

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
* Removed `numpy-base` dependency and `USE_NUMPY_BASE` environment variable from conda recipe [gh-124](https://github.com/IntelPython/mkl_random/pull/124)
1414

1515
### Fixed
16+
* Fixed compatibility with NumPy 2.5 by replacing the deprecated in-place array `shape` assignment with `reshape`, and by replacing the deprecated `numpy.testing.suppress_warnings` usage in tests with `pytest.warns` [gh-137](https://github.com/IntelPython/mkl_random/pull/137)
1617

1718
## [1.4.1] (05/11/2026)
1819

mkl_random/mklrand.pyx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ cdef object vec_cont1_array(
591591
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
592592
for i from 0 <= i < multi_nd:
593593
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
594-
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
594+
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
595595
multi_ndim = len(multi_shape)
596596
arr_obj = arr_obj.transpose(
597597
tuple(range(multi_ndim, arr_obj.ndim))
@@ -688,7 +688,7 @@ cdef object vec_cont2_array(
688688
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
689689
for i from 0 <= i < multi_nd:
690690
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
691-
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
691+
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
692692
multi_ndim = len(multi_shape)
693693
arr_obj = arr_obj.transpose(
694694
tuple(range(multi_ndim, arr_obj.ndim))
@@ -800,7 +800,7 @@ cdef object vec_cont3_array(
800800
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
801801
for i from 0 <= i < multi_nd:
802802
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
803-
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
803+
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
804804
multi_ndim = len(multi_shape)
805805
arr_obj = arr_obj.transpose(
806806
tuple(range(multi_ndim, arr_obj.ndim))
@@ -920,7 +920,7 @@ cdef object vec_discnp_array(
920920
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
921921
for i from 0 <= i < multi_nd:
922922
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
923-
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
923+
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
924924
multi_ndim = len(multi_shape)
925925
arr_obj = arr_obj.transpose(
926926
tuple(range(multi_ndim, arr_obj.ndim))
@@ -1019,7 +1019,7 @@ cdef object vec_discdd_array(
10191019
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
10201020
for i from 0 <= i < multi_nd:
10211021
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
1022-
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
1022+
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
10231023
multi_ndim = len(multi_shape)
10241024
arr_obj = arr_obj.transpose(
10251025
tuple(range(multi_ndim, arr_obj.ndim))
@@ -1137,7 +1137,7 @@ cdef object vec_discnmN_array(
11371137
multi_shape = cpython.tuple.PyTuple_New(multi_nd)
11381138
for i from 0 <= i < multi_nd:
11391139
cpython.tuple.PyTuple_SetItem(multi_shape, i, multi_dims[i])
1140-
arr_obj.shape = (multi_shape + arr_obj.shape)[:arr_obj.ndim]
1140+
arr_obj = arr_obj.reshape((multi_shape + arr_obj.shape)[:arr_obj.ndim])
11411141
multi_ndim = len(multi_shape)
11421142
arr_obj = arr_obj.transpose(
11431143
tuple(range(multi_ndim, arr_obj.ndim))
@@ -1243,7 +1243,9 @@ cdef object vec_discd_array(
12431243
func(state, n, array_data + n*i, oa_data[0])
12441244
cnp.PyArray_MultiIter_NEXTi(multi, 1)
12451245
arr_obj = <object>array
1246-
arr_obj.shape = ((<object>oa).shape + arr_obj.shape)[:arr_obj.ndim]
1246+
arr_obj = arr_obj.reshape(
1247+
((<object>oa).shape + arr_obj.shape)[:arr_obj.ndim]
1248+
)
12471249
arr_obj = arr_obj.transpose(
12481250
tuple(range(oa.ndim, arr_obj.ndim))
12491251
+ tuple(range(0, oa.ndim))
@@ -1302,7 +1304,9 @@ cdef object vec_long_discd_array(
13021304
func(state, n, array_data + n*i, oa_data[0])
13031305
cnp.PyArray_MultiIter_NEXTi(multi, 1)
13041306
arr_obj = <object>array
1305-
arr_obj.shape = ((<object> oa).shape + arr_obj.shape)[:arr_obj.ndim]
1307+
arr_obj = arr_obj.reshape(
1308+
((<object> oa).shape + arr_obj.shape)[:arr_obj.ndim]
1309+
)
13061310
arr_obj = arr_obj.transpose(
13071311
tuple(range(oa.ndim, arr_obj.ndim))
13081312
+ tuple(range(0, oa.ndim))
@@ -1355,9 +1359,9 @@ cdef object vec_Poisson_array(
13551359
func2(state, n, array_data + n*i, oa_data[0])
13561360
cnp.PyArray_MultiIter_NEXTi(multi, 1)
13571361
arr_obj = <object>array
1358-
arr_obj.shape = (
1362+
arr_obj = arr_obj.reshape((
13591363
(<object>olambda).shape + arr_obj.shape
1360-
)[:arr_obj.ndim]
1364+
)[:arr_obj.ndim])
13611365
arr_obj = arr_obj.transpose(
13621366
tuple(range(olambda.ndim, arr_obj.ndim))
13631367
+ tuple(range(0, olambda.ndim))
@@ -6222,7 +6226,7 @@ cdef class _MKLRandomState:
62226226

62236227
x = np.dot(x, np.sqrt(s)[:, None] * v)
62246228
x += mean
6225-
x.shape = tuple(final_shape)
6229+
x = x.reshape(tuple(final_shape))
62266230
return x
62276231

62286232
def multinomial(self, int n, object pvals, size=None):

mkl_random/tests/test_random.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
assert_equal,
3535
assert_no_warnings,
3636
assert_raises,
37-
suppress_warnings,
3837
)
3938

4039
import mkl_random as rnd
@@ -386,10 +385,8 @@ def test_randomdist_randint(randomdist):
386385

387386
def test_randomdist_random_integers(randomdist):
388387
rnd.seed(randomdist.seed, brng=randomdist.brng)
389-
with suppress_warnings() as sup:
390-
w = sup.record(DeprecationWarning)
388+
with pytest.warns(DeprecationWarning):
391389
actual = rnd.random_integers(-99, 99, size=(3, 2))
392-
assert len(w) == 1
393390

394391
desired = np.array([[96, -96], [-64, 42], [4, 97]])
395392
np.testing.assert_array_equal(actual, desired)
@@ -401,10 +398,8 @@ def test_random_integers_max_int():
401398
# into a C long. Previous implementations of this
402399
# method have thrown an OverflowError when attempting
403400
# to generate this integer.
404-
with suppress_warnings() as sup:
405-
w = sup.record(DeprecationWarning)
401+
with pytest.warns(DeprecationWarning):
406402
actual = rnd.random_integers(np.iinfo("l").max, np.iinfo("l").max)
407-
assert len(w) == 1
408403
desired = np.iinfo("l").max
409404
np.testing.assert_equal(actual, desired)
410405

0 commit comments

Comments
 (0)