Ops...numpy crashing during pygmt import ?!

I just got a message that numpy 2.0 is released (NumPy 2.0 migration guide — NumPy v2.1.dev0 Manual) and curisouly, I was testing a notebook for a class and got this error. (I’m using colab).

from pygmt.datasets import load_earth_relief
# load the default grid (gridline-registered 1 arc-degree grid)
grid = load_earth_relief()

ModuleNotFoundError Traceback (most recent call last)
in <cell line: 1>()
----> 1 from pygmt.datasets import load_earth_relief
2 # load the default grid (gridline-registered 1 arc-degree grid)
3 grid = load_earth_relief()

11 frames
/usr/local/lib/python3.10/site-packages/xarray/core/nputils.py in
13 # remove once numpy 2.0 is the oldest supported version
14 if module_available(“numpy”, minversion=“2.0.0.dev0”):
—> 15 from numpy.lib.array_utils import ( # type: ignore[import-not-found,unused-ignore]
16 normalize_axis_index,
17 )

ModuleNotFoundError: No module named ‘numpy.lib.array_utils’

Do you think there will be incompatibility problems in the near future ?

Hmm, the error seems to be on xarray/core/nputils.py, not PyGMT. Try upgrading to xarray=2024.06.0 and see if the problem goes away?

Oh, and just as a general comment, the current PyGMT v0.12.0 version should be mostly compatible with NumPy 2.0. We’ve been testing this new version since Jul 2023, and it’s been surprisingly smooth.

That said, there was one internal function (pygmt.clib.conversion.dataarray_to_matrix) we had to modify slightly to get the same repr output between NumPy 1.26 and NumPy 2.0 (see Failing doctest on pygmt.clib.conversion.dataarray_to_matrix with NumPy 2.0 · Issue #2628 · GenericMappingTools/pygmt · GitHub), but that shouldn’t affect most people, and we’ve released a patch already that will go into v0.13.0.

1 Like

Hey @weiji14 … you are right ! and in fact, I hade the bad luck to test a notebook between updates of the COLAB VMs :joy: So, there was a major upgrade and everything is working fine now.

1 Like