Skip to content

Commit 2d7f12e

Browse files
author
Release Manager
committed
sagemathgh-39242: Make tests compatible with numpy 2.1 Related to sagemath#38250 . In numpy 2.1 it returns a `Token` object which gets printed out. This assigns it to `_`. ### 📝 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. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39242 Reported by: user202729 Reviewer(s): Tobias Diez, user202729
2 parents d8a4722 + ba71bbd commit 2d7f12e

File tree

15 files changed

+21
-21
lines changed

15 files changed

+21
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ the standard deviation::
2525

2626
sage: import numpy as np
2727
sage: if int(np.version.short_version[0]) > 1:
28-
....: np.set_printoptions(legacy="1.25")
28+
....: _ = np.set_printoptions(legacy="1.25")
2929
sage: np.mean([1, 2, 3, 5])
3030
2.75
3131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import it.
88

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

1313
The basic object of computation in NumPy is an array. It is simple to
1414
create an array.

src/sage/combinat/fully_packed_loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _make_color_list(n, colors=None, color_map=None, randomize=False):
6868
6969
sage: import numpy as np
7070
sage: if int(np.version.short_version[0]) > 1:
71-
....: np.set_printoptions(legacy="1.25")
71+
....: _ = np.set_printoptions(legacy="1.25")
7272
sage: from sage.combinat.fully_packed_loop import _make_color_list
7373
sage: _make_color_list(5)
7474
sage: _make_color_list(5, ['blue', 'red'])

src/sage/functions/special.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class SphericalHarmonic(BuiltinFunction):
218218
0.345494149471335
219219
sage: import numpy as np # needs scipy
220220
sage: if int(np.version.short_version[0]) > 1: # needs scipy
221-
....: np.set_printoptions(legacy="1.25") # needs scipy
221+
....: _ = np.set_printoptions(legacy="1.25") # needs scipy
222222
sage: import scipy.version
223223
sage: if scipy.version.version < '1.15.0':
224224
....: from scipy.special import sph_harm # NB: arguments x and y are swapped # needs scipy

src/sage/numerical/optimize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def minimize(func, x0, gradient=None, hessian=None, algorithm='default',
381381
....: return sum(100.0r*(x[1r:]-x[:-1r]**2.0r)**2.0r + (1r-x[:-1r])**2.0r)
382382
sage: import numpy
383383
sage: if int(numpy.version.short_version[0]) > 1:
384-
....: numpy.set_printoptions(legacy="1.25")
384+
....: _ = numpy.set_printoptions(legacy="1.25")
385385
sage: from numpy import zeros
386386
sage: def rosen_der(x):
387387
....: xm = x[1r:-1r]

src/sage/plot/arrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_minmax_data(self):
5555
5656
sage: import numpy # to ensure numpy 2.0 compatibility
5757
sage: if int(numpy.version.short_version[0]) > 1:
58-
....: numpy.set_printoptions(legacy="1.25")
58+
....: _ = numpy.set_printoptions(legacy="1.25")
5959
sage: from sage.plot.arrow import CurveArrow
6060
sage: b = CurveArrow(path=[[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]],
6161
....: options={})

src/sage/plot/multigraphics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def _add_subplot(self, figure, index, **options):
766766
(0.2, 0.3, 0.4, 0.1)
767767
sage: import numpy # to ensure numpy 2.0 compatibility
768768
sage: if int(numpy.version.short_version[0]) > 1:
769-
....: numpy.set_printoptions(legacy="1.25")
769+
....: _ = numpy.set_printoptions(legacy="1.25")
770770
sage: ax1.get_position().bounds # tol 1.0e-13
771771
(0.2, 0.3, 0.4000000000000001, 0.10000000000000003)
772772
"""
@@ -1269,7 +1269,7 @@ def position(self, index):
12691269
sage: G = graphics_array([g1, g2])
12701270
sage: import numpy # to ensure numpy 2.0 compatibility
12711271
sage: if int(numpy.version.short_version[0]) > 1:
1272-
....: numpy.set_printoptions(legacy="1.25")
1272+
....: _ = numpy.set_printoptions(legacy="1.25")
12731273
sage: G.position(0) # tol 5.0e-3
12741274
(0.025045451349937315,
12751275
0.03415488992713045,

src/sage/plot/streamline_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_minmax_data(self):
7272
sage: x, y = var('x y')
7373
sage: import numpy # to ensure numpy 2.0 compatibility
7474
sage: if int(numpy.version.short_version[0]) > 1:
75-
....: numpy.set_printoptions(legacy="1.25")
75+
....: _ = numpy.set_printoptions(legacy="1.25")
7676
sage: d = streamline_plot((.01*x, x+y), (x,10,20), (y,10,20))[0].get_minmax_data()
7777
sage: d['xmin']
7878
10.0

src/sage/rings/integer.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
595595
sage: # needs numpy
596596
sage: import numpy
597597
sage: if int(numpy.version.short_version[0]) > 1:
598-
....: numpy.set_printoptions(legacy="1.25")
598+
....: _ = numpy.set_printoptions(legacy="1.25")
599599
sage: numpy.int8('12') == 12
600600
True
601601
sage: 12 == numpy.int8('12')

src/sage/rings/real_mpfi.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ TESTS::
252252
253253
sage: import numpy # needs numpy
254254
sage: if int(numpy.version.short_version[0]) > 1: # needs numpy
255-
....: numpy.set_printoptions(legacy="1.25") # needs numpy
255+
....: _ = numpy.set_printoptions(legacy="1.25") # needs numpy
256256
sage: RIF(2) == numpy.int8('2') # needs numpy
257257
True
258258
sage: numpy.int8('2') == RIF(2) # needs numpy

0 commit comments

Comments
 (0)