Skip to content

Commit 7741d06

Browse files
seismanweiji14
andauthored
Remove the dependency of netCDF4 (#3643)
Co-authored-by: Wei Ji <[email protected]>
1 parent ae82fd6 commit 7741d06

16 files changed

+19
-19
lines changed

.github/workflows/benchmarks.yml

-1
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

-1
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

-1
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

-1
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

+2-3
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ 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 \
153+
numpy pandas xarray packaging \
154154
build contextily dvc geopandas ipython pyarrow rioxarray \
155155
pytest pytest-cov pytest-doctestplus pytest-mpl pytest-rerunfailures \
156-
sphinx-gallery
156+
netCDF4 sphinx-gallery
157157
158158
# Show installed pkg information for postmortem diagnostic
159159
- name: List installed packages

.github/workflows/ci_tests_legacy.yaml

-1
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

+1-1
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

-1
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

+2-3
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.13 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.13 numpy pandas xarray packaging gmt
139138
```
140139
:::
141140
::::

environment.yml

+1-1
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,7 @@ dependencies:
3433
- pytest-cov
3534
- pytest-doctestplus
3635
- pytest-mpl
36+
- netCDF4
3737
# Dev dependencies (building documentation)
3838
- geodatasets
3939
- myst-nb

pygmt/tests/test_io.py

+2
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
# TODO(PyGMT>=0.20.0): Remove test_io_load_dataarray
1416
def test_io_load_dataarray():

pygmt/tests/test_xarray_accessor.py

+5-1
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,6 +15,8 @@
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_xarray_accessor_gridline_cartesian():
1922
"""
@@ -102,6 +105,7 @@ def test_xarray_accessor_set_invalid_registration_and_gtype():
102105

103106

104107
# TODO(GMT>=6.5.0): Remove the xfail marker for GMT>=6.5.0.
108+
@pytest.mark.skipif(condition=not _HAS_NETCDF4, reason="netCDF4 is not installed")
105109
@pytest.mark.xfail(
106110
condition=sys.platform == "win32" and Version(__gmt_version__) < Version("6.5.0"),
107111
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7573",
@@ -119,7 +123,7 @@ def test_xarray_accessor_sliced_datacube():
119123
"https://github.com/pydata/xarray-data/raw/master/eraint_uvz.nc",
120124
download="u",
121125
)
122-
with xr.open_dataset(fname) as dataset:
126+
with xr.open_dataset(fname, engine="netcdf4") as dataset:
123127
grid = dataset.sel(level=500, month=1, drop=True).z
124128

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

pygmt/tests/test_xarray_backend.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Tests for xarray 'gmt' backend engine.
33
"""
44

5+
import importlib
56
import re
67

78
import numpy as np
@@ -12,8 +13,11 @@
1213
from pygmt.exceptions import GMTInvalidInput
1314
from pygmt.helpers import GMTTempFile
1415

16+
_HAS_NETCDF4 = bool(importlib.util.find_spec("netCDF4"))
17+
1518

1619
@pytest.mark.benchmark
20+
@pytest.mark.skipif(condition=not _HAS_NETCDF4, reason="netCDF4 is not installed")
1721
def test_xarray_backend_load_dataarray():
1822
"""
1923
Check that xarray.load_dataarray works to read a netCDF grid with

pyproject.toml

-1
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

-1
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)