diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index b14f930..0399d4d 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -48,7 +48,7 @@ jobs: - name: Install the package run: | set -e - python -m pip install cog3pio[tests] --find-links dist --force-reinstall + python -m pip install cog3pio[benchmark,tests] --find-links dist --force-reinstall python -m pip list # Run the benchmark tests diff --git a/pyproject.toml b/pyproject.toml index a8bcc1e..8ce3f88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,9 +21,12 @@ dependencies = [ dynamic = ["version"] [project.optional-dependencies] +benchmark = [ + "pytest-codspeed", + "rioxarray", +] tests = [ "pytest", - "pytest-codspeed", ] [project.entry-points."xarray.backends"] diff --git a/python/tests/test_xarray_backend.py b/python/tests/test_xarray_backend.py index 191f314..a9da6cb 100644 --- a/python/tests/test_xarray_backend.py +++ b/python/tests/test_xarray_backend.py @@ -2,13 +2,36 @@ Tests for xarray 'cog3pio' backend engine. """ +import numpy as np +import pytest import xarray as xr +try: + import rioxarray + + HAS_RIOXARRAY = True +except ImportError: + HAS_RIOXARRAY = False + # %% -def test_xarray_backend_cog3pio(): +@pytest.mark.benchmark +@pytest.mark.parametrize( + "engine", + [ + "cog3pio", + pytest.param( + "rasterio", + marks=pytest.mark.skipif( + condition=not HAS_RIOXARRAY, reason="Could not import 'rioxarray'" + ), + ), + ], +) +def test_xarray_backend_open_dataarray(engine): """ - Ensure that passing engine='cog3pio' to xarray.open_dataarray works. + Ensure that passing engine='cog3pio' to xarray.open_dataarray works, and benchmark + against engine="rasterio" (rioxarray). """ with xr.open_dataarray( filename_or_obj="https://github.com/cogeotiff/rio-tiler/raw/6.4.1/tests/fixtures/cog_nodata_nan.tif", @@ -20,3 +43,4 @@ def test_xarray_backend_cog3pio(): assert da.y.min() == 5190440.0 assert da.y.max() == 5300040.0 assert da.dtype == "float32" + np.testing.assert_allclose(actual=da.mean(), desired=0.08855476)