Skip to content

Conversation

seisman
Copy link
Member

@seisman seisman commented Sep 16, 2025

Following SPEC0 policy, NumPy 1.26 should be dropped in 2025 quarter 3.

Bumps the minimum supported NumPy version to 2.0 in the following files:

  • .github/workflows/ci_tests.yaml
  • .github/workflows/ci_tests_legacy.yaml
  • environment.yml
  • pyproject.toml
  • requirements.txt
  • Remove workarounds for unsupported versions

Supersedes #3916.

@seisman seisman added this to the 0.17.0 milestone Sep 16, 2025
@seisman seisman added the maintenance Boring but important stuff for the core devs label Sep 16, 2025
@seisman seisman marked this pull request as draft September 16, 2025 14:27
@seisman
Copy link
Member Author

seisman commented Sep 16, 2025

https://github.com/GenericMappingTools/pygmt/actions/runs/17768889118/job/50499354183?pr=4090
The Python 3.11 CI job fails with the following error:

  error    libmamba Could not solve for environment specs
      The following packages are incompatible
      ├─ numpy =2.0 * is requested and can be installed;
      └─ xarray =2023.7 * is not installable because it requires
         └─ numpy >=1.21,<2.0a0 *, which conflicts with any installable versions previously reported.
  critical libmamba Could not solve for environment specs

Likely need to bump xarray first. See #4091.

The Python 3.11 CI job has two failing tests due to the removal of the conftest.py file. The failures are related to #2628. I think we should fix them to match the behavior of NumPy>=2.0

=================================== FAILURES ===================================
__________________ [doctest] pygmt.datatypes.image._GMT_IMAGE __________________
063 1 0
064 >>> x  # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
065 array([-179.5, -178.5, ..., 178.5, 179.5])
066 >>> y  # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
067 array([ 89.5,  88.5, ..., -88.5, -89.5])
068 >>> data.dtype
069 dtype('uint8')
070 >>> data.shape
071 (180, 360, 3)
072 >>> data.min(), data.max()
Expected:
    (10, 255)
Got:
    (np.uint8(10), np.uint8(255))

/home/runner/work/pygmt/pygmt/pygmt/datatypes/image.py:72: DocTestFailure
_____________ [doctest] pygmt.datatypes.image._GMT_IMAGE.to_xarray _____________
109 --------
110 >>> from pygmt.clib import Session
111 >>> with Session() as lib:
112 ...     with lib.virtualfile_out(kind="image") as voutimg:
113 ...         lib.call_module("read", ["@earth_day_01d", voutimg, "-Ti"])
114 ...         # Read the image from the virtual file
115 ...         image = lib.read_virtualfile(voutimg, kind="image")
116 ...         # Convert to xarray.DataArray and use it later
117 ...         da = image.contents.to_xarray()
118 >>> da  # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Differences (unified diff with -expected +actual):
    @@ -1,3 +1,3 @@
    -<xarray.DataArray 'z' (band: 3, y: 180, x: 360)>...
    +<xarray.DataArray 'z' (band: 3, y: 180, x: 360)> Size: 194kB
     array([[[ 10,  10,  10, ...,  10,  10,  10],
             [ 10,  10,  10, ...,  10,  10,  10],
    @@ -22,9 +22,10 @@
             [177, 179, 179, ..., 178, 177, 177],
             [185, 187, 187, ..., 187, 186, 185],
    -        [189, 191, 191, ..., 191, 191, 189]]], dtype=uint8)
    +        [189, 191, 191, ..., 191, 191, 189]]],
    +      shape=(3, 180, 360), dtype=uint8)
     Coordinates:
    -  * y        (y) float64... 89.5 88.5 87.5 86.5 ... -86.5 -87.5 -88.5 -89.5
    -  * x        (x) float64... -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5
    -  * band     (band) uint8... 1 2 3
    +  * y        (y) float64 1kB 89.5 88.5 87.5 86.5 ... -86.5 -87.5 -88.5 -89.5
    +  * x        (x) float64 3kB -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5
    +  * band     (band) uint8 3B 1 2 3
     Attributes:
    -    long_name:     z
    +    long_name:  z

@seisman seisman changed the title SPEC 0: Bump minimum supported versions to NumPy 2.0 SPEC 0: Bump minimum supported version to NumPy 2.0 Sep 16, 2025
@seisman seisman marked this pull request as ready for review September 17, 2025 00:48
@seisman seisman added needs review This PR has higher priority and needs review. and removed needs review This PR has higher priority and needs review. labels Sep 17, 2025
@weiji14
Copy link
Member

weiji14 commented Sep 17, 2025

      The following packages are incompatible
      ├─ numpy =2.0 * is requested and can be installed;
      └─ xarray =2023.10 * is not installable because there are no viable options
         ├─ xarray 2023.10.0 would require
         │  └─ numpy >=1.21,<2.0a0 *, which conflicts with any installable versions previously reported;
         └─ xarray [2023.10.0|2023.10.1] would require
            └─ numpy >=1.22,<2.0a0 *, which conflicts with any installable versions previously reported.

There is a numpy<2.0 pin set at conda-forge/conda-forge-repodata-patches-feedstock#728, we might need to bump xarray higher, to 2024.5.0 I think?

@seisman
Copy link
Member Author

seisman commented Sep 17, 2025

https://github.com/GenericMappingTools/pygmt/actions/runs/17768889118/job/50499354183?pr=4090 The Python 3.11 CI job fails with the following error:

  error    libmamba Could not solve for environment specs
      The following packages are incompatible
      ├─ numpy =2.0 * is requested and can be installed;
      └─ xarray =2023.7 * is not installable because it requires
         └─ numpy >=1.21,<2.0a0 *, which conflicts with any installable versions previously reported.
  critical libmamba Could not solve for environment specs

Likely need to bump xarray first. See #4091.

Still failing. The minimum xarray version compatible with numpy 2.0 is xarray 2024.5:

$ mamba search xarray=2024.5 --info                                                                                                                                                         Loading channels: done
xarray 2024.5.0 pyhd8ed1ab_0
----------------------------
file name   : xarray-2024.5.0-pyhd8ed1ab_0.conda
name        : xarray
version     : 2024.5.0
build       : pyhd8ed1ab_0
build number: 0
size        : 768 KB
license     : Apache-2.0
subdir      : noarch
url         : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch/xarray-2024.5.0-pyhd8ed1ab_0.conda
md5         : e839fd0ae78a368c930f0b1feafa6736
timestamp   : 2024-05-13 13:49:27 UTC
constraints :
  - hdf5 >=1.12
  - distributed >=2023.4
  - nc-time-axis >=1.4
  - cartopy >=0.21
  - h5py >=3.8
  - h5netcdf >=1.1
  - toolz >=0.12
  - dask-core >=2023.4
  - pint >=0.22
  - scipy >=1.10
  - numba >=0.56
  - cftime >=1.6
  - seaborn-base >=0.12
  - iris >=3.4
  - zarr >=2.14
  - flox >=0.7
  - bottleneck >=1.3
  - sparse >=0.14
  - matplotlib-base >=3.7
  - netcdf4 >=1.6.0
dependencies:
  - numpy >=1.23
  - packaging >=23.1
  - pandas >=2.0
  - python >=3.9


$ mamba search xarray=2024.3 --info
Loading channels: done
xarray 2024.3.0 pyhd8ed1ab_0
----------------------------
file name   : xarray-2024.3.0-pyhd8ed1ab_0.conda
name        : xarray
version     : 2024.3.0
build       : pyhd8ed1ab_0
build number: 0
size        : 747 KB
license     : Apache-2.0
subdir      : noarch
url         : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch/xarray-2024.3.0-pyhd8ed1ab_0.conda
md5         : 772d7ee42b65d0840130eabd5bd3fc17
timestamp   : 2024-03-29 19:57:37 UTC
constraints :
  - bottleneck >=1.3
  - sparse >=0.13
  - nc-time-axis >=1.4
  - scipy >=1.8
  - zarr >=2.12
  - flox >=0.5
  - netcdf4 >=1.6.0
  - cartopy >=0.20
  - h5netcdf >=1.0
  - dask-core >=2022.7
  - cftime >=1.6
  - numba >=0.55
  - hdf5 >=1.12
  - iris >=3.2
  - toolz >=0.12
  - h5py >=3.6
  - distributed >=2022.7
  - matplotlib-base >=3.5
  - seaborn-base >=0.11
  - pint >=0.19
dependencies:
  - numpy >=1.23,<2.0a0
  - packaging >=22
  - pandas >=1.5
  - python >=3.9

I guess we need to either bump to xarray 2024.5 now or wait until 2026 quarter 2.

@weiji14
Copy link
Member

weiji14 commented Sep 17, 2025

I guess we need to either bump to xarray 2024.5 now or wait until 2026 quarter 2.

xarray=2024.06.0 according to numpy/numpy#26191 (comment) (unsure if it's the repodata patch that's wrong, or that linked thread is wrong, but I did find pydata/xarray#8946).

How about we delay the numpy 2.0+ bump for another quarter, i.e. leave this PR in draft until November/December 2025?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants