Skip to content

Conversation

tornaria
Copy link
Contributor

📚 Description

Mostly due to a deprecation warning:
Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.).

Also fix:

  • a change of output in numpy.linalg.eig()
  • a change in an exception class

See: #35081

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.

Mostly due to a deprecation warning:
`Conversion of an array with ndim > 0 to a scalar is deprecated, and
will error in future. Ensure you extract a single element from your
array before performing this operation. (Deprecated NumPy 1.25.)`.

Also fix:
 - a change of output in `numpy.linalg.eig()`
 - a change in an exception class
@github-actions
Copy link

Documentation preview for this PR (built with commit 941ca85; changes) is ready! 🎉

@antonio-rojas
Copy link
Contributor

Works for me

@vbraun vbraun merged commit ecfe06b into sagemath:develop Jul 1, 2023
@collares
Copy link
Contributor

collares commented Jul 31, 2023

src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py also triggers the same deprecation warning described in this PR, because Sage's flatten function converts a 2-dimensional numpy.ndarray into a list of 1-dimensional numpy.ndarrays. Replacing Sage's flatten by numpy's as in the patch below does work, but I am not sure if patching Sagebook tests is desirable or if it's the best solution:

diff --git a/src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py
b/src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py 
index aa153fd4cd..eebbe87aff 100644 
--- a/src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py 
+++ b/src/sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py 
@@ -134,11 +134,11 @@ Sage example in ./graphique.tex, line 1120:: 
  sage: t = srange(0, 5, 0.1); p = Graphics() 
  sage: for k in srange(0, 10, 0.15): 
  ....:       y = integrate.odeint(f, k, t) 
-  ....:       p += line(zip(t, flatten(y))) 
+  ....:       p += line(zip(t, y.flatten())) 
  sage: t = srange(0, -5, -0.1); q = Graphics() 
  sage: for k in srange(0, 10, 0.15): 
  ....:       y = integrate.odeint(f, k, t) 
-  ....:       q += line(zip(t, flatten(y))) 
+  ....:       q += line(zip(t, y.flatten())) 
  sage: y = var('y') 
  sage: v = plot_vector_field((1, -cos(x*y)), (x,-5,5), (y,-2,11)) 
  sage: g = p + q + v; g.show()

Another option would be to explicitly ignore the deprecation warning in the doctest. @tornaria @mkoeppe @antonio-rojas any suggestions?

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.

5 participants