Skip to content

Commit 17d570e

Browse files
authored
SPEC 0: Bump minimum supported version to NumPy 2.0 and Xarray 2024.5 (#4090)
1 parent ce57041 commit 17d570e

File tree

12 files changed

+45
-65
lines changed

12 files changed

+45
-65
lines changed

.github/workflows/ci_tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ jobs:
7272
include:
7373
# Python 3.11 + core packages (minimum supported versions) + optional packages (minimum supported versions if any)
7474
- python-version: '3.11'
75-
numpy-version: '1.26'
75+
numpy-version: '2.0'
7676
pandas-version: '=2.2'
77-
xarray-version: '=2023.10'
77+
xarray-version: '=2024.5'
7878
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray netCDF4 sphinx-gallery'
7979
# Python 3.13 + core packages (latest versions) + optional packages
8080
- python-version: '3.13'

.github/workflows/ci_tests_legacy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ jobs:
6161
python=3.11
6262
gmt=${{ matrix.gmt_version }}
6363
ghostscript
64-
numpy=1.26
64+
numpy=2.0
6565
pandas=2.2
66-
xarray=2023.10
66+
xarray=2024.5
6767
packaging=24.2
6868
contextily=1.5
6969
geopandas=1.0

environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ dependencies:
77
# Required dependencies
88
- gmt=6.6.0
99
- ghostscript=10.06.0
10-
- numpy>=1.26
10+
- numpy>=2.0
1111
- pandas>=2.2
12-
- xarray>=2023.10
12+
- xarray>=2024.5
1313
- packaging>=24.2
1414
# Optional dependencies
1515
- contextily>=1.5

pygmt/conftest.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

pygmt/datasets/tile_map.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ def load_tile_map(
122122
... )
123123
>>> raster.sizes
124124
Frozen({'band': 3, 'y': 256, 'x': 512})
125-
>>> raster.coords # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
125+
>>> raster.coords
126126
Coordinates:
127-
* band (band) uint8... 1 2 3
128-
* y (y) float64... -7.081e-10 -7.858e+04 ... -1.996e+07 -2.004e+07
129-
* x (x) float64... -2.004e+07 -1.996e+07 ... 1.996e+07 2.004e+07
130-
spatial_ref int... 0
127+
* band (band) uint8 3B 1 2 3
128+
* y (y) float64 2kB -7.081e-10 -7.858e+04 ... -1.996e+07 -2.004e+07
129+
* x (x) float64 4kB -2.004e+07 -1.996e+07 ... 1.996e+07 2.004e+07
130+
spatial_ref int64 8B 0
131131
>>> # CRS is set only if rioxarray is available
132132
>>> if hasattr(raster, "rio"):
133133
... raster.rio.crs.to_string()

pygmt/datatypes/grid.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def to_xarray(self) -> xr.DataArray:
114114
... grid = lib.read_virtualfile(voutgrd, kind="grid")
115115
... # Convert to xarray.DataArray and use it later
116116
... da = grid.contents.to_xarray()
117-
>>> da # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
118-
<xarray.DataArray 'z' (lat: 14, lon: 8)>...
117+
>>> da
118+
<xarray.DataArray 'z' (lat: 14, lon: 8)> Size: 448B
119119
array([[347.5, 344.5, 386. , 640.5, 617. , 579. , 646.5, 671. ],
120120
[383. , 284.5, 344.5, 394. , 491. , 556.5, 578.5, 618.5],
121121
[373. , 367.5, 349. , 352.5, 419.5, 428. , 570. , 667.5],
@@ -132,32 +132,32 @@ def to_xarray(self) -> xr.DataArray:
132132
[347.5, 331.5, 309. , 282. , 190. , 208. , 299.5, 348. ]],
133133
dtype=float32)
134134
Coordinates:
135-
* lat (lat) float64... -23.5 -22.5 -21.5 -20.5 ... -12.5 -11.5 -10.5
136-
* lon (lon) float64... -54.5 -53.5 -52.5 -51.5 -50.5 -49.5 -48.5 -47.5
135+
* lat (lat) float64 112B -23.5 -22.5 -21.5 -20.5 ... -12.5 -11.5 -10.5
136+
* lon (lon) float64 64B -54.5 -53.5 -52.5 -51.5 -50.5 -49.5 -48.5 -47.5
137137
Attributes:
138138
Conventions: CF-1.7
139139
title: Produced by grdcut
140140
history: grdcut @earth_relief_01d_p -R-55/-47/-24/-10 -Gstatic_ea...
141141
description: Reduced by Gaussian Cartesian filtering (111.2 km fullwi...
142142
actual_range: [190. 981.]
143143
long_name: elevation (m)
144-
>>> da.coords["lon"] # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
145-
<xarray.DataArray 'lon' (lon: 8)>...
144+
>>> da.coords["lon"]
145+
<xarray.DataArray 'lon' (lon: 8)> Size: 64B
146146
array([-54.5, -53.5, -52.5, -51.5, -50.5, -49.5, -48.5, -47.5])
147147
Coordinates:
148-
* lon (lon) float64... -54.5 -53.5 -52.5 -51.5 -50.5 -49.5 -48.5 -47.5
148+
* lon (lon) float64 64B -54.5 -53.5 -52.5 -51.5 -50.5 -49.5 -48.5 -47.5
149149
Attributes:
150150
long_name: longitude
151151
units: degrees_east
152152
standard_name: longitude
153153
axis: X
154154
actual_range: [-55. -47.]
155-
>>> da.coords["lat"] # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
156-
<xarray.DataArray 'lat' (lat: 14)>...
155+
>>> da.coords["lat"]
156+
<xarray.DataArray 'lat' (lat: 14)> Size: 112B
157157
array([-23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5, -15.5, -14.5,
158-
-13.5, -12.5, -11.5, -10.5])
158+
-13.5, -12.5, -11.5, -10.5])
159159
Coordinates:
160-
* lat (lat) float64... -23.5 -22.5 -21.5 -20.5 ... -12.5 -11.5 -10.5
160+
* lat (lat) float64 112B -23.5 -22.5 -21.5 -20.5 ... -12.5 -11.5 -10.5
161161
Attributes:
162162
long_name: latitude
163163
units: degrees_north

pygmt/datatypes/image.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ class _GMT_IMAGE(ctp.Structure): # noqa: N801
6767
[2, 2, 2, 2]
6868
b'BRPa' 0.5
6969
1 0
70-
>>> x # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
70+
>>> x
7171
array([-179.5, -178.5, ..., 178.5, 179.5])
72-
>>> y # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
72+
>>> y
7373
array([ 89.5, 88.5, ..., -88.5, -89.5])
7474
>>> data.dtype
7575
dtype('uint8')
7676
>>> data.shape
7777
(180, 360, 3)
7878
>>> data.min(), data.max()
79-
(10, 255)
79+
(np.uint8(10), np.uint8(255))
8080
"""
8181

8282
_fields_: ClassVar = [
@@ -121,7 +121,7 @@ def to_xarray(self) -> xr.DataArray:
121121
... image = lib.read_virtualfile(voutimg, kind="image")
122122
... # Convert to xarray.DataArray and use it later
123123
... da = image.contents.to_xarray()
124-
>>> da # doctest: +NORMALIZE_WHITESPACE
124+
>>> da
125125
<xarray.DataArray 'z' (band: 3, y: 180, x: 360)> Size: 194kB
126126
array([[[ 10, 10, 10, ..., 10, 10, 10],
127127
[ 10, 10, 10, ..., 10, 10, 10],
@@ -145,24 +145,25 @@ def to_xarray(self) -> xr.DataArray:
145145
...,
146146
[177, 179, 179, ..., 178, 177, 177],
147147
[185, 187, 187, ..., 187, 186, 185],
148-
[189, 191, 191, ..., 191, 191, 189]]], dtype=uint8)
148+
[189, 191, 191, ..., 191, 191, 189]]],
149+
shape=(3, 180, 360), dtype=uint8)
149150
Coordinates:
150151
* band (band) uint8 3B 1 2 3
151152
* y (y) float64 1kB 89.5 88.5 87.5 86.5 ... -86.5 -87.5 -88.5 -89.5
152153
* x (x) float64 3kB -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5
153154
Attributes:
154155
long_name: z
155156
156-
>>> da.coords["x"] # doctest: +NORMALIZE_WHITESPACE
157+
>>> da.coords["x"]
157158
<xarray.DataArray 'x' (x: 360)> Size: 3kB
158-
array([-179.5, -178.5, -177.5, ..., 177.5, 178.5, 179.5])
159+
array([-179.5, -178.5, -177.5, ..., 177.5, 178.5, 179.5], shape=(360,))
159160
Coordinates:
160161
* x (x) float64 3kB -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5
161162
Attributes:
162163
long_name: x
163164
axis: X
164165
actual_range: [-180. 180.]
165-
>>> da.coords["y"] # doctest: +NORMALIZE_WHITESPACE
166+
>>> da.coords["y"]
166167
<xarray.DataArray 'y' (y: 180)> Size: 1kB
167168
array([ 89.5, 88.5, 87.5, 86.5, ..., -87.5, -88.5, -89.5])
168169
Coordinates:

pygmt/helpers/decorators.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,7 @@ def use_alias(**aliases):
514514
R = bla J = meh
515515
>>> my_module(region="bla", projection="meh")
516516
R = bla J = meh
517-
>>> my_module(
518-
... region="bla", projection="meh", J="bla"
519-
... ) # doctest: +NORMALIZE_WHITESPACE
517+
>>> my_module(region="bla", projection="meh", J="bla")
520518
Traceback (most recent call last):
521519
...
522520
pygmt.exceptions.GMTInvalidInput:

pygmt/tests/test_clib_to_numpy.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import datetime
6-
import sys
76

87
import numpy as np
98
import numpy.testing as npt
@@ -52,14 +51,7 @@ def _check_result(result, expected_dtype):
5251
@pytest.mark.parametrize(
5352
("data", "expected_dtype"),
5453
[
55-
# TODO(NumPy>=2.0): Remove the if-else statement after NumPy>=2.0.
56-
pytest.param(
57-
[1, 2, 3],
58-
np.int32
59-
if sys.platform == "win32" and Version(np.__version__) < Version("2.0")
60-
else np.int64,
61-
id="int",
62-
),
54+
pytest.param([1, 2, 3], np.int64, id="int"),
6355
pytest.param([1.0, 2.0, 3.0], np.float64, id="float"),
6456
pytest.param(
6557
[complex(+1), complex(-2j), complex("-Infinity+NaNj")],

pygmt/xarray/backend.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ class GMTBackendEntrypoint(BackendEntrypoint):
5050
>>> da_grid = xr.open_dataarray(
5151
... "@static_earth_relief.nc", engine="gmt", raster_kind="grid"
5252
... )
53-
>>> da_grid # doctest: +NORMALIZE_WHITESPACE
53+
>>> da_grid
5454
<xarray.DataArray 'z' (lat: 14, lon: 8)> Size: 448B
5555
[112 values with dtype=float32]
5656
Coordinates:
5757
* lat (lat) float64 112B -23.5 -22.5 -21.5 -20.5 ... -12.5 -11.5 -10.5
5858
* lon (lon) float64 64B -54.5 -53.5 -52.5 -51.5 -50.5 -49.5 -48.5 -47.5
59-
Attributes:...
59+
Attributes:
6060
Conventions: CF-1.7
6161
title: Produced by grdcut
6262
history: grdcut @earth_relief_01d_p -R-55/-47/-24/-10 -Gstatic_eart...
@@ -69,14 +69,14 @@ class GMTBackendEntrypoint(BackendEntrypoint):
6969
>>> da_image = xr.open_dataarray(
7070
... "@earth_night_01d", engine="gmt", raster_kind="image"
7171
... )
72-
>>> da_image # doctest: +NORMALIZE_WHITESPACE
72+
>>> da_image
7373
<xarray.DataArray 'z' (band: 3, y: 180, x: 360)> Size: 194kB
7474
[194400 values with dtype=uint8]
7575
Coordinates:
76-
* band (band) uint8... 1 2 3
77-
* y (y) float64... 89.5 88.5 87.5 86.5 ... -86.5 -87.5 -88.5 -89.5
78-
* x (x) float64... -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5
79-
Attributes:...
76+
* band (band) uint8 3B 1 2 3
77+
* y (y) float64 1kB 89.5 88.5 87.5 86.5 ... -86.5 -87.5 -88.5 -89.5
78+
* x (x) float64 3kB -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5
79+
Attributes:
8080
long_name: z
8181
8282
Load a single-band netCDF file using ``raster_kind="grid"`` over a bounding box
@@ -95,7 +95,7 @@ class GMTBackendEntrypoint(BackendEntrypoint):
9595
Coordinates:
9696
* lat (lat) float64 104B 32.0 32.08 32.17 32.25 ... 32.83 32.92 33.0
9797
* lon (lon) float64 200B -64.0 -63.92 -63.83 ... -62.17 -62.08 -62.0
98-
Attributes:...
98+
Attributes:
9999
Conventions: CF-1.7
100100
title: ETOPO5 global topography
101101
history: grdreformat -fg bermuda.grd bermuda.nc=ns

0 commit comments

Comments
 (0)