diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index d00c8b78f1d..3052ca02c17 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -60,7 +60,6 @@ jobs: numpy pandas xarray - netCDF4 packaging geopandas pyarrow-core diff --git a/.github/workflows/cache_data.yaml b/.github/workflows/cache_data.yaml index 64c00d46d51..3aee5bc7710 100644 --- a/.github/workflows/cache_data.yaml +++ b/.github/workflows/cache_data.yaml @@ -55,7 +55,6 @@ jobs: numpy pandas xarray - netCDF4 packaging python-build diff --git a/.github/workflows/ci_docs.yml b/.github/workflows/ci_docs.yml index 08d608dd260..25830a52d7d 100644 --- a/.github/workflows/ci_docs.yml +++ b/.github/workflows/ci_docs.yml @@ -96,7 +96,6 @@ jobs: numpy pandas xarray - netCDF4 packaging contextily geopandas diff --git a/.github/workflows/ci_doctests.yaml b/.github/workflows/ci_doctests.yaml index 19b67c471f6..ebf721950e6 100644 --- a/.github/workflows/ci_doctests.yaml +++ b/.github/workflows/ci_doctests.yaml @@ -54,7 +54,6 @@ jobs: numpy pandas xarray - netCDF4 packaging contextily geopandas diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index e424ca9a638..5fbbde2ec5c 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -75,13 +75,13 @@ jobs: numpy-version: '1.26' pandas-version: '=2.1' xarray-version: '=2023.07' - optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray sphinx-gallery' + optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray netCDF4 sphinx-gallery' # Python 3.13 + core packages (latest versions) + optional packages - python-version: '3.13' numpy-version: '2.2' pandas-version: '' xarray-version: '' - optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray sphinx-gallery' + optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray netCDF4 sphinx-gallery' # Python 3.12 + core packages (Linux only) - os: 'ubuntu-latest' python-version: '3.12' @@ -129,7 +129,6 @@ jobs: numpy=${{ matrix.numpy-version }} pandas${{ matrix.pandas-version }} xarray${{ matrix.xarray-version }} - netCDF4 packaging make pip diff --git a/.github/workflows/ci_tests_dev.yaml b/.github/workflows/ci_tests_dev.yaml index b117e35a6ca..c648ea89a74 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -150,10 +150,10 @@ jobs: run: | python -m pip install --pre --prefer-binary \ --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \ - numpy pandas xarray netCDF4 packaging \ + numpy pandas xarray packaging \ build contextily dvc geopandas ipython pyarrow rioxarray \ pytest pytest-cov pytest-doctestplus pytest-mpl pytest-rerunfailures \ - sphinx-gallery + netCDF4 sphinx-gallery # Show installed pkg information for postmortem diagnostic - name: List installed packages diff --git a/.github/workflows/ci_tests_legacy.yaml b/.github/workflows/ci_tests_legacy.yaml index 72d28443382..6701461da62 100644 --- a/.github/workflows/ci_tests_legacy.yaml +++ b/.github/workflows/ci_tests_legacy.yaml @@ -64,7 +64,6 @@ jobs: numpy=1.26 pandas xarray - netCDF4 packaging contextily=1.5 geopandas=1.0 diff --git a/.github/workflows/type_checks.yml b/.github/workflows/type_checks.yml index ea6ff22218e..8c377c06723 100644 --- a/.github/workflows/type_checks.yml +++ b/.github/workflows/type_checks.yml @@ -53,7 +53,7 @@ jobs: # 3. type checker and stub packages # 4. other packages that are used somewhere in PyGMT python -m pip install \ - numpy pandas xarray netcdf4 packaging \ + numpy pandas xarray packaging \ contextily geopandas ipython pyarrow rioxarray \ mypy pandas-stubs pyarrow-stubs \ matplotlib pytest diff --git a/ci/requirements/docs.yml b/ci/requirements/docs.yml index 5ec39050558..efde2e0f620 100644 --- a/ci/requirements/docs.yml +++ b/ci/requirements/docs.yml @@ -10,7 +10,6 @@ dependencies: - numpy - pandas - xarray - - netCDF4 - packaging # Optional dependencies - contextily diff --git a/doc/install.md b/doc/install.md index 55d2290295f..fdd33e7ba80 100644 --- a/doc/install.md +++ b/doc/install.md @@ -95,7 +95,6 @@ PyGMT requires the following packages to be installed: - [NumPy](https://numpy.org) - [pandas](https://pandas.pydata.org) - [Xarray](https://xarray.dev/) -- [netCDF4](https://unidata.github.io/netcdf4-python) - [packaging](https://packaging.pypa.io) :::{note} @@ -128,14 +127,14 @@ installed (we'll call it `pygmt` but feel free to change it to whatever you want ::: {tab-item} mamba :sync: mamba ``` -mamba create --name pygmt python=3.13 numpy pandas xarray netcdf4 packaging gmt +mamba create --name pygmt python=3.13 numpy pandas xarray packaging gmt ``` ::: ::: {tab-item} conda :sync: conda ``` -conda create --name pygmt python=3.13 numpy pandas xarray netcdf4 packaging gmt +conda create --name pygmt python=3.13 numpy pandas xarray packaging gmt ``` ::: :::: diff --git a/environment.yml b/environment.yml index f7b26d6ff3f..05e18df3426 100644 --- a/environment.yml +++ b/environment.yml @@ -10,7 +10,6 @@ dependencies: - numpy>=1.26 - pandas>=2.1 - xarray>=2023.07 - - netCDF4 - packaging # Optional dependencies - contextily>=1.5 @@ -34,6 +33,7 @@ dependencies: - pytest-cov - pytest-doctestplus - pytest-mpl + - netCDF4 # Dev dependencies (building documentation) - geodatasets - myst-nb diff --git a/pygmt/tests/test_io.py b/pygmt/tests/test_io.py index 62cee34fbbf..f797245632a 100644 --- a/pygmt/tests/test_io.py +++ b/pygmt/tests/test_io.py @@ -9,6 +9,8 @@ from pygmt.helpers import GMTTempFile from pygmt.io import load_dataarray +pytest.importorskip("netCDF4") + # TODO(PyGMT>=0.20.0): Remove test_io_load_dataarray def test_io_load_dataarray(): diff --git a/pygmt/tests/test_xarray_accessor.py b/pygmt/tests/test_xarray_accessor.py index f8930e74eb4..4967d37e6ce 100644 --- a/pygmt/tests/test_xarray_accessor.py +++ b/pygmt/tests/test_xarray_accessor.py @@ -2,6 +2,7 @@ Test the behaviour of the GMTDataArrayAccessor class. """ +import importlib import sys from pathlib import Path @@ -14,6 +15,8 @@ from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput +_HAS_NETCDF4 = bool(importlib.util.find_spec("netCDF4")) + def test_xarray_accessor_gridline_cartesian(): """ @@ -102,6 +105,7 @@ def test_xarray_accessor_set_invalid_registration_and_gtype(): # TODO(GMT>=6.5.0): Remove the xfail marker for GMT>=6.5.0. +@pytest.mark.skipif(condition=not _HAS_NETCDF4, reason="netCDF4 is not installed") @pytest.mark.xfail( condition=sys.platform == "win32" and Version(__gmt_version__) < Version("6.5.0"), reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7573", @@ -119,7 +123,7 @@ def test_xarray_accessor_sliced_datacube(): "https://github.com/pydata/xarray-data/raw/master/eraint_uvz.nc", download="u", ) - with xr.open_dataset(fname) as dataset: + with xr.open_dataset(fname, engine="netcdf4") as dataset: grid = dataset.sel(level=500, month=1, drop=True).z assert grid.gmt.registration == GridRegistration.GRIDLINE diff --git a/pygmt/tests/test_xarray_backend.py b/pygmt/tests/test_xarray_backend.py index c62b720b429..70f469914d7 100644 --- a/pygmt/tests/test_xarray_backend.py +++ b/pygmt/tests/test_xarray_backend.py @@ -2,6 +2,7 @@ Tests for xarray 'gmt' backend engine. """ +import importlib import re import numpy as np @@ -12,8 +13,11 @@ from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile +_HAS_NETCDF4 = bool(importlib.util.find_spec("netCDF4")) + @pytest.mark.benchmark +@pytest.mark.skipif(condition=not _HAS_NETCDF4, reason="netCDF4 is not installed") def test_xarray_backend_load_dataarray(): """ Check that xarray.load_dataarray works to read a netCDF grid with diff --git a/pyproject.toml b/pyproject.toml index dbacb85b392..82b07cd59f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,6 @@ dependencies = [ "numpy>=1.26", "pandas>=2.1", "xarray>=2023.07", - "netCDF4", "packaging", ] dynamic = ["version"] diff --git a/requirements.txt b/requirements.txt index 8071b554512..48e2c87bbb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,4 @@ numpy>=1.26 pandas>=2.1 xarray>=2023.07 -netCDF4 packaging