Skip to content

Commit 0962e0b

Browse files
author
Release Manager
committed
gh-38250: provide compatibility with numpy 2.0 This will fix #38242 Basically, most of the problems are with numpy switching to a different way to display its data, showing type. We either use a compatibility version, or add ellipses in doctests. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x ] The title is concise and informative. - [x ] The description explains in detail what this PR is about. - [x ] I have linked a relevant issue or discussion. - [x ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #38250 Reported by: Dima Pasechnik Reviewer(s):
2 parents 8a986ac + 515d20e commit 0962e0b

36 files changed

+116
-25
lines changed

src/doc/en/faq/faq-usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ ints. For example::
324324
sage: RealNumber = float; Integer = int
325325
sage: from scipy import stats
326326
sage: stats.ttest_ind([1,2,3,4,5], [2,3,4,5,.6])
327-
Ttest...Result(statistic=0.0767529..., pvalue=0.940704...)
327+
Ttest...Result(statistic=...0.0767529..., pvalue=...0.940704...)
328328
sage: stats.uniform(0,15).ppf([0.5,0.7])
329329
array([ 7.5, 10.5])
330330

src/doc/en/prep/Quickstarts/Statistics-and-Distributions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ NumPy provides, for example, functions to compute the arithmetic mean and
2424
the standard deviation::
2525

2626
sage: import numpy as np
27+
sage: if int(np.version.short_version[0]) > 1:
28+
....: np.set_printoptions(legacy="1.25")
2729
sage: np.mean([1, 2, 3, 5])
2830
2.75
2931

src/doc/en/thematic_tutorials/numerical_sage/numpy.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import it.
77
::
88

99
sage: import numpy
10+
sage: if int(numpy.version.short_version[0]) > 1:
11+
....: numpy.set_printoptions(legacy="1.25") # to ensure numpy 2.0 compatibility
1012

1113
The basic object of computation in NumPy is an array. It is simple to
1214
create an array.

src/doc/it/faq/faq-usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ anziché Integer di Sage. Ad esempio::
305305
sage: RealNumber = float; Integer = int
306306
sage: from scipy import stats
307307
sage: stats.ttest_ind([1,2,3,4,5], [2,3,4,5,.6])
308-
Ttest...Result(statistic=0.0767529..., pvalue=0.940704...)
308+
Ttest...Result(statistic=...0.0767529..., pvalue=...0.940704...)
309309
sage: stats.uniform(0,15).ppf([0.5,0.7])
310310
array([ 7.5, 10.5])
311311

src/sage/arith/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,7 @@ def power_mod(a, n, m):
22772277
22782278
sage: from numpy import int32 # needs numpy
22792279
sage: power_mod(int32(2), int32(390), int32(391)) # needs numpy
2280-
285
2280+
...285...
22812281
sage: from gmpy2 import mpz
22822282
sage: power_mod(mpz(2), mpz(390), mpz(391))
22832283
mpz(285)

src/sage/calculus/interpolators.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Development supported by NSF award No. 0702939.
2727
import numpy as np
2828
cimport numpy as np
2929

30+
if int(np.version.short_version[0]) > 1:
31+
np.set_printoptions(legacy="1.25")
32+
3033
from math import pi
3134
cdef double TWOPI = 2*pi
3235

src/sage/calculus/riemann.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ from sage.calculus.integration import numerical_integral
4444
import numpy as np
4545
cimport numpy as np
4646

47+
if int(np.version.short_version[0]) > 1:
48+
np.set_printoptions(legacy="1.25")
49+
4750
from math import pi
4851
from math import sin
4952
from math import cos

src/sage/combinat/fully_packed_loop.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def _make_color_list(n, colors=None, color_map=None, randomize=False):
6666
r"""
6767
TESTS::
6868
69+
sage: import numpy as np
70+
sage: if int(np.version.short_version[0]) > 1:
71+
....: np.set_printoptions(legacy="1.25")
6972
sage: from sage.combinat.fully_packed_loop import _make_color_list
7073
sage: _make_color_list(5)
7174
sage: _make_color_list(5, ['blue', 'red'])

src/sage/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def sage_include_directories(use_sources=False):
296296
sage: import sage.env
297297
sage: sage.env.sage_include_directories()
298298
['...',
299-
'.../numpy/core/include',
299+
'.../numpy/...core/include',
300300
'.../include/python...']
301301
302302
To check that C/C++ files are correctly found, we verify that we can

src/sage/functions/special.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ class SphericalHarmonic(BuiltinFunction):
217217
sage: spherical_harmonic(1, 1, pi/2, pi).n() # abs tol 1e-14 # needs sage.symbolic
218218
0.345494149471335
219219
sage: from scipy.special import sph_harm # NB: arguments x and y are swapped # needs scipy
220+
sage: import numpy as np # needs scipy
221+
sage: if int(np.version.short_version[0]) > 1: # needs scipy
222+
....: np.set_printoptions(legacy="1.25") # needs scipy
220223
sage: sph_harm(1, 1, pi.n(), (pi/2).n()) # abs tol 1e-14 # needs scipy sage.symbolic
221224
(0.3454941494713355-4.231083042742082e-17j)
222225

0 commit comments

Comments
 (0)