Repository: sagemath/sage

Issue:
Update numpy to 1.26
<div id="comment:0"></div>

https://github.com/numpy/numpy/releases

1.26.0.b1 is out, with Python 3.12 support and Cython 3 compatibility.


- Depends on #35404 

CC:  @antonio-rojas @kiwifb @tornaria

Component: **packages: standard**

_Issue created by migration from https://trac.sagemath.org/ticket/34816_




Discussion:
Branch: **[u/mkoeppe/update_numpy_to_1_24](https://github.com/sagemath/sagetrac-mirror/tree/u/mkoeppe/update_numpy_to_1_24)**
<div id="comment:2" align="right">comment:2</div>

There are a bunch of new `FutureWarning`s:

```
    FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.  (This may have returned Python scalars in past versions.

    FutureWarning: In the future `np.bytes` will be defined as the corresponding NumPy scalar.  (This may have returned Python scalars in past versions.
```
and also:

```
sage -t --random-seed=208794765845619979520719224489586219359 src/sage/plot/histogram.py
**********************************************************************
File "src/sage/plot/histogram.py", line 94, in sage.plot.histogram.Histogram.get_minmax_data
Failed example:
    h.get_minmax_data()
Exception raised:
    Traceback (most recent call last):
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 695, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 1093, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.plot.histogram.Histogram.get_minmax_data[9]>", line 1, in <module>
        h.get_minmax_data()
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/plot/histogram.py", line 116, in get_minmax_data
        ydata, xdata = numpy.histogram(self.datalist, **opt)
      File "<__array_function__ internals>", line 198, in histogram
    TypeError: histogram() got an unexpected keyword argument 'normed'

sage -t --random-seed=208794765845619979520719224489586219359 src/sage/plot/plot_field.py
**********************************************************************
File "src/sage/plot/plot_field.py", line 51, in sage.plot.plot_field.PlotField.__init__
Failed example:
    r.yvec_array
Expected:
    masked_array(data=[0.0, 0.70710678118..., 0.70710678118...,
                       0.89442719...],
                 mask=[False, False, False, False],
           fill_value=1e+20)
Got:
    masked_array(data=[0.        , 0.70710678, 0.70710678, 0.89442719],
                 mask=False,
           fill_value=1e+20)

sage -t --random-seed=208794765845619979520719224489586219359 src/sage/misc/persist.pyx
**********************************************************************
File "src/sage/misc/persist.pyx", line 159, in sage.misc.persist.load
Failed example:
    hello
Expected:
    <fortran object>
Got:
    <fortran function hello>

sage -t --random-seed=208794765845619979520719224489586219359 src/sage/plot/complex_plot.pyx
**********************************************************************
File "src/sage/plot/complex_plot.pyx", line 1025, in sage.plot.complex_plot.?
Failed example:
    complex_plot(f, (0, 1), (0, 1), plot_points=300,
                 contoured=True, contour_type='linear', contour_base=1)
Expected:
    Graphics object consisting of 1 graphics primitive
Got:
    doctest:warning
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/bin/sage-runtests", line 154, in <module>
        err = DC.run()
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/control.py", line 1384, in run
        self.run_doctests()
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/control.py", line 1059, in run_doctests
        self.dispatcher.dispatch()
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 2021, in dispatch
        self.parallel_dispatch()
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 1916, in parallel_dispatch
        w.start()  # This might take some time
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 2190, in start
        super().start()
      File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 121, in start
        self._popen = self._Popen(self)
      File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/context.py", line 224, in _Popen
        return _default_context.get_context().Process._Popen(process_obj)
      File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/context.py", line 281, in _Popen
        return Popen(process_obj)
      File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
        self._launch(process_obj)
      File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/popen_fork.py", line 71, in _launch
        code = process_obj._bootstrap(parent_sentinel=child_r)
      File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
        self.run()
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 2162, in run
        task(self.options, self.outtmpfile, msgpipe, self.result_queue)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 2492, in __call__
        doctests, extras = self._run(runner, options, results)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 2544, in _run
        result = runner.run(test)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 866, in run
        return self._run(test, compileflags, out)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 695, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/doctest/forker.py", line 1093, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.plot.complex_plot.?[14]>", line 1, in <module>
        complex_plot(f, (Integer(0), Integer(1)), (Integer(0), Integer(1)), plot_points=Integer(300),
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/repl/rich_output/display_manager.py", line 827, in displayhook
        plain_text, rich_output = self._rich_output_formatter(obj, dict())
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/repl/rich_output/display_manager.py", line 645, in _rich_output_formatter
        rich_output = self._call_rich_repr(obj, rich_repr_kwds)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/repl/rich_output/display_manager.py", line 605, in _call_rich_repr
        return obj._rich_repr_(self)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/plot/graphics.py", line 1001, in _rich_repr_
        return display_manager.graphics_from_save(
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/repl/rich_output/display_manager.py", line 733, in graphics_from_save
        save_function(filename, **kwds)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/misc/decorators.py", line 410, in wrapper
        return func(*args, **kwds)
      File "/Users/mkoeppe/s/sage/sage-rebasing/src/sage/plot/graphics.py", line 3358, in save
        figure.savefig(filename, **opts)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/figure.py", line 3046, in savefig
        self.canvas.print_figure(fname, **kwargs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 2295, in print_figure
        self.figure.draw(renderer)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 73, in draw_wrapper
        result = draw(artist, renderer, *args, **kwargs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
        return draw(artist, renderer)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/figure.py", line 2837, in draw
        mimage._draw_list_compositing_images(
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
        a.draw(renderer)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
        return draw(artist, renderer)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3091, in draw
        mimage._draw_list_compositing_images(
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
        a.draw(renderer)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
        return draw(artist, renderer)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/image.py", line 646, in draw
        im, l, b, trans = self.make_image(
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/image.py", line 956, in make_image
        return self._make_image(self._A, bbox, transformed_bbox, clip,
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/image.py", line 564, in _make_image
        output = self.to_rgba(output, bytes=True, norm=False)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/cm.py", line 440, in to_rgba
        xx = (xx * 255).astype(np.uint8)
      File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/warnings.py", line 109, in _showwarnmsg
        sw(msg.message, msg.category, msg.filename, msg.lineno,
    :
    RuntimeWarning: invalid value encountered in cast

```

---
New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/77b9aabd41160356609d5447f7bf0d2615cd00aa"><code>77b9aab</code></a></td><td><code>build/pkgs/numpy: Update to 1.24.0rc1</code></td></tr></table>

Commit: **[`77b9aab`](https://github.com/sagemath/sagetrac-mirror/commit/77b9aabd41160356609d5447f7bf0d2615cd00aa)**
<div id="comment:3"></div>

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/9e95fc3e745aaf923a5843e3ec793eae03c99af0"><code>9e95fc3</code></a></td><td><code>build/pkgs/numpy: Update to 1.24.0rc1</code></td></tr><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/f8d8b51fecc800af14461c41b9fb515ef0cd4c6d"><code>f8d8b51</code></a></td><td><code>build/pkgs/numpy: Update to 1.24.0rc2</code></td></tr></table>

Changed commit from **[`77b9aab`](https://github.com/sagemath/sagetrac-mirror/commit/77b9aabd41160356609d5447f7bf0d2615cd00aa)** to **[`f8d8b51`](https://github.com/sagemath/sagetrac-mirror/commit/f8d8b51fecc800af14461c41b9fb515ef0cd4c6d)**
Description changed:
``````diff
--- 
+++ 
@@ -1,2 +1,3 @@
-1.24.0rc1 is out
+1.24.0 is out - https://numpy.org/doc/stable/release/1.24.0-notes.html
 
+
``````

<div id="comment:5"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/23e777eda58c06ec28d2c0e3f2e29b3b088168f7"><code>23e777e</code></a></td><td><code>build/pkgs/numpy: Update to 1.24.0</code></td></tr></table>

Changed commit from **[`f8d8b51`](https://github.com/sagemath/sagetrac-mirror/commit/f8d8b51fecc800af14461c41b9fb515ef0cd4c6d)** to **[`23e777e`](https://github.com/sagemath/sagetrac-mirror/commit/23e777eda58c06ec28d2c0e3f2e29b3b088168f7)**
Description changed:
``````diff
--- 
+++ 
@@ -1,3 +1,3 @@
-1.24.0 is out - https://numpy.org/doc/stable/release/1.24.0-notes.html
+1.24.1 is out - https://numpy.org/doc/stable/release/1.24.0-notes.html
 
 
``````

<div id="comment:8" align="right">comment:8</div>

The following seems to fix everything for me (numpy 1.24.1 from system)

```
diff --git a/src/sage/misc/persist.pyx b/src/sage/misc/persist.pyx
index 3ac5f1cc2b0..cb1f327c199 100644
--- a/src/sage/misc/persist.pyx
+++ b/src/sage/misc/persist.pyx
@@ -157,7 +157,7 @@ def load(*filename, compress=True, verbose=True, **kwargs):
         ....:     _ = f.write(code)
         sage: load(t)
         sage: hello
-        <fortran object>
+        <fortran ...>
     """
     import sage.repl.load
     if len(filename) != 1:
diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx
index 6f0aeab87ae..b77c69b2f77 100644
--- a/src/sage/plot/complex_plot.pyx
+++ b/src/sage/plot/complex_plot.pyx
@@ -461,6 +461,8 @@ def complex_to_rgb(z_values, contoured=False, tiled=False,
             rgb[i, j, 2] = b
 
     sig_off()
+    nan_indices = np.isnan(rgb).any(-1)     # Mask for undefined points
+    rgb[nan_indices] = 1                    # Make nan_indices white
     return rgb
 
 
diff --git a/src/sage/plot/histogram.py b/src/sage/plot/histogram.py
index 3bc2b76b58e..388c2d1391d 100644
--- a/src/sage/plot/histogram.py
+++ b/src/sage/plot/histogram.py
@@ -87,13 +87,8 @@ class Histogram(GraphicPrimitive):
 
         TESTS::
 
-            sage: h = histogram([10,3,5], normed=True)[0]
-            doctest:warning...:
-            DeprecationWarning: the 'normed' option is deprecated. Use 'density' instead.
-            See https://trac.sagemath.org/25260 for details.
+            sage: h = histogram([10,3,5], density=True)[0]
             sage: h.get_minmax_data()
-            doctest:warning ...
-            ...VisibleDeprecationWarning: Passing `normed=True` on non-uniform bins has always been broken, and computes neither the probability density function nor the probability mass function. The result is only correct if the bins are uniform, when density=True will produce the same result anyway. The argument will be removed in a future version of numpy.
             {'xmax': 10.0, 'xmin': 3.0, 'ymax': 0.476190476190..., 'ymin': 0}
         """
         import numpy
diff --git a/src/sage/repl/ipython_extension.py b/src/sage/repl/ipython_extension.py
index 798671aab42..cad6a47ca8b 100644
--- a/src/sage/repl/ipython_extension.py
+++ b/src/sage/repl/ipython_extension.py
@@ -405,7 +405,7 @@ class SageMagics(Magics):
             ....: C END FILE FIB1.F
             ....: ''')
             sage: fib
-            <fortran object>
+            <fortran ...>
             sage: from numpy import array
             sage: a = array(range(10), dtype=float)
             sage: fib(a, 10)
```
Removed branch from the issue description because it is replaced by PR #35081 

Resolving patch:
diff --git a/build/pkgs/numpy/lapack_conf.py b/build/pkgs/numpy/lapack_conf.py
deleted file mode 100644
--- a/build/pkgs/numpy/lapack_conf.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python3
-
-import pkgconfig, os
-
-conf_file=open('site.cfg', 'w')
-
-pc_blas   = pkgconfig.parse('cblas blas')
-pc_lapack = pkgconfig.parse('lapack')
-
-if os.environ['UNAME'] == 'Darwin':
-    # on macOS, if openblas is available (the default), use it instead of the
-    # macOS Accelerate framework
-    if 'openblas' in pc_blas.get('libraries', []):
-        conf_file.write('[openblas]\n')
-        conf_file.write('libraries    = '+', '.join(pc_blas['libraries'])+'\n')
-        inc_dir = pc_blas['include_dirs']
-        if len(inc_dir) > 0:
-            conf_file.write('include_dirs = '+ ':'.join(inc_dir)+'\n')
-        lib_dir = pc_blas['library_dirs']
-        if len(lib_dir) > 0:
-            conf_file.write('library_dirs = '+ ':'.join(lib_dir)+'\n')
-else:
-    conf_file.write('[blas]\n')
-    inc_dir = pc_blas['include_dirs']
-    if len(inc_dir) > 0:
-        conf_file.write('include_dirs = '+ ':'.join(inc_dir)+'\n')
-    lib_dir = pc_blas['library_dirs']
-    if len(lib_dir) > 0:
-        conf_file.write('library_dirs = '+ ':'.join(lib_dir)+'\n')
-    conf_file.write('blas_libs    = '+', '.join(pc_blas['libraries'])+'\n')
-    conf_file.write('[lapack]\n')
-    lib_dir = pc_lapack['library_dirs']
-    if len(lib_dir) > 0:
-        conf_file.write('library_dirs = '+ ':'.join(lib_dir)+'\n')
-    conf_file.write('lapack_libs  = '+', '.join(pc_lapack['libraries'])+'\n')
-
-conf_file.close()
diff --git a/src/sage/repl/ipython_kernel/kernel.py b/src/sage/repl/ipython_kernel/kernel.py
--- a/src/sage/repl/ipython_kernel/kernel.py
+++ b/src/sage/repl/ipython_kernel/kernel.py
@@ -16,7 +16,18 @@
 # ***************************************************************************
 
 import sys
-from ipykernel.ipkernel import IPythonKernel
+import warnings
+with warnings.catch_warnings():
+    # When upstream pydevd (as opposed to the bundled version) is used
+    # with debugpy, a PEP 420 warning is emitted. Debugpy and/or
+    # pydevd will eventually work around this, but as of September
+    # 2023, hiding the warning gives us more flexibility in the
+    # versions of those packages that we can accept.
+    warnings.filterwarnings("ignore",
+                            message=r".*pkg_resources\.declare_namespace",
+                            category=DeprecationWarning)
+    from ipykernel.ipkernel import IPythonKernel
+
 from ipykernel.zmqshell import ZMQInteractiveShell
 from traitlets import Type
 


Test patch: