Skip to content

Commit e6b98f3

Browse files
committed
netCDF4 is no longer a required dependency
1 parent ecb933c commit e6b98f3

15 files changed

+18
-21
lines changed

.github/workflows/benchmarks.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ jobs:
6060
numpy
6161
pandas
6262
xarray
63-
netCDF4
6463
packaging
6564
geopandas
6665
pyarrow-core

.github/workflows/cache_data.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ jobs:
5555
numpy
5656
pandas
5757
xarray
58-
netCDF4
5958
packaging
6059
python-build
6160

.github/workflows/ci_docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ jobs:
9696
numpy
9797
pandas
9898
xarray
99-
netCDF4
10099
packaging
101100
contextily
102101
geopandas

.github/workflows/ci_doctests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ jobs:
5454
numpy
5555
pandas
5656
xarray
57-
netCDF4
5857
packaging
5958
contextily
6059
geopandas

.github/workflows/ci_tests.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ jobs:
7575
numpy-version: '1.26'
7676
pandas-version: '=2.1'
7777
xarray-version: '=2023.07'
78-
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray sphinx-gallery'
78+
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'
8181
numpy-version: '2.2'
8282
pandas-version: ''
8383
xarray-version: ''
84-
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray sphinx-gallery'
84+
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray netCDF4 sphinx-gallery'
8585
# Python 3.12 + core packages (Linux only)
8686
- os: 'ubuntu-latest'
8787
python-version: '3.12'
@@ -129,7 +129,6 @@ jobs:
129129
numpy=${{ matrix.numpy-version }}
130130
pandas${{ matrix.pandas-version }}
131131
xarray${{ matrix.xarray-version }}
132-
netCDF4
133132
packaging
134133
make
135134
pip

.github/workflows/ci_tests_dev.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ jobs:
150150
run: |
151151
python -m pip install --pre --prefer-binary \
152152
--extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
153-
numpy pandas xarray netCDF4 packaging \
154-
build contextily dvc geopandas ipython pyarrow rioxarray \
153+
numpy pandas xarray packaging \
154+
build contextily dvc geopandas ipython pyarrow rioxarray netCDF4 \
155155
pytest pytest-cov pytest-doctestplus pytest-mpl pytest-rerunfailures \
156156
sphinx-gallery
157157

.github/workflows/ci_tests_legacy.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ jobs:
6464
numpy=1.26
6565
pandas
6666
xarray
67-
netCDF4
6867
packaging
6968
contextily=1.5
7069
geopandas=1.0

.github/workflows/type_checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
# 3. type checker and stub packages
5454
# 4. other packages that are used somewhere in PyGMT
5555
python -m pip install \
56-
numpy pandas xarray netcdf4 packaging \
56+
numpy pandas xarray packaging \
5757
contextily geopandas ipython pyarrow rioxarray \
5858
mypy pandas-stubs pyarrow-stubs \
5959
matplotlib pytest

ci/requirements/docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dependencies:
1010
- numpy
1111
- pandas
1212
- xarray
13-
- netCDF4
1413
- packaging
1514
# Optional dependencies
1615
- contextily

doc/install.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ PyGMT requires the following packages to be installed:
9595
- [NumPy](https://numpy.org)
9696
- [pandas](https://pandas.pydata.org)
9797
- [Xarray](https://xarray.dev/)
98-
- [netCDF4](https://unidata.github.io/netcdf4-python)
9998
- [packaging](https://packaging.pypa.io)
10099

101100
:::{note}
@@ -128,14 +127,14 @@ installed (we'll call it `pygmt` but feel free to change it to whatever you want
128127
::: {tab-item} mamba
129128
:sync: mamba
130129
```
131-
mamba create --name pygmt python=3.13 numpy pandas xarray netcdf4 packaging gmt
130+
mamba create --name pygmt python=3.12 numpy pandas xarray packaging gmt
132131
```
133132
:::
134133

135134
::: {tab-item} conda
136135
:sync: conda
137136
```
138-
conda create --name pygmt python=3.13 numpy pandas xarray netcdf4 packaging gmt
137+
conda create --name pygmt python=3.12 numpy pandas xarray packaging gmt
139138
```
140139
:::
141140
::::

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dependencies:
1010
- numpy>=1.26
1111
- pandas>=2.1
1212
- xarray>=2023.07
13-
- netCDF4
1413
- packaging
1514
# Optional dependencies
1615
- contextily>=1.5
@@ -34,6 +33,8 @@ dependencies:
3433
- pytest-cov
3534
- pytest-doctestplus
3635
- pytest-mpl
36+
# Dev dependencies (testing)
37+
- netCDF4
3738
# Dev dependencies (building documentation)
3839
- geodatasets
3940
- myst-nb

pygmt/tests/test_accessor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test the behaviour of the GMTDataArrayAccessor class.
33
"""
44

5+
import importlib
56
import sys
67
from pathlib import Path
78

@@ -14,14 +15,16 @@
1415
from pygmt.enums import GridRegistration, GridType
1516
from pygmt.exceptions import GMTInvalidInput
1617

18+
_HAS_NETCDF4 = bool(importlib.util.find_spec("netCDF4"))
19+
1720

1821
def test_accessor_gridline_cartesian():
1922
"""
2023
Check that the accessor returns the correct registration and gtype values for a
2124
Cartesian, gridline-registered grid.
2225
"""
2326
fname = which(fname="@test.dat.nc", download="a")
24-
grid = xr.open_dataarray(fname, engine="netcdf4")
27+
grid = xr.load_dataarray(fname, engine="gmt", raster_kind="grid")
2528
assert grid.gmt.registration == GridRegistration.GRIDLINE
2629
assert grid.gmt.gtype == GridType.CARTESIAN
2730

@@ -32,7 +35,7 @@ def test_accessor_pixel_geographic():
3235
geographic, pixel-registered grid.
3336
"""
3437
fname = which(fname="@earth_relief_01d_p", download="a")
35-
grid = xr.open_dataarray(fname, engine="netcdf4")
38+
grid = xr.load_dataarray(fname, engine="gmt", raster_kind="grid")
3639
assert grid.gmt.registration == GridRegistration.PIXEL
3740
assert grid.gmt.gtype == GridType.GEOGRAPHIC
3841

@@ -104,6 +107,7 @@ def test_accessor_set_invalid_registration_and_gtype():
104107

105108

106109
# TODO(GMT>=6.5.0): Remove the xfail marker for GMT>=6.5.0.
110+
@pytest.mark.skipif(condition=not _HAS_NETCDF4, reason="netCDF4 is not installed")
107111
@pytest.mark.xfail(
108112
condition=sys.platform == "win32" and Version(__gmt_version__) < Version("6.5.0"),
109113
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7573",
@@ -121,7 +125,7 @@ def test_accessor_sliced_datacube():
121125
"https://github.com/pydata/xarray-data/raw/master/eraint_uvz.nc",
122126
download="u",
123127
)
124-
with xr.open_dataset(fname) as dataset:
128+
with xr.open_dataset(fname, engine="netcdf4") as dataset:
125129
grid = dataset.sel(level=500, month=1, drop=True).z
126130

127131
assert grid.gmt.registration == GridRegistration.GRIDLINE

pygmt/tests/test_io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from pygmt.helpers import GMTTempFile
1010
from pygmt.io import load_dataarray
1111

12+
pytest.importorskip("netCDF4")
13+
1214

1315
@pytest.mark.benchmark
1416
def test_io_load_dataarray():

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ dependencies = [
3838
"numpy>=1.26",
3939
"pandas>=2.1",
4040
"xarray>=2023.07",
41-
"netCDF4",
4241
"packaging",
4342
]
4443
dynamic = ["version"]

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
numpy>=1.26
33
pandas>=2.1
44
xarray>=2023.07
5-
netCDF4
65
packaging

0 commit comments

Comments
 (0)