Skip to content

Commit

Permalink
BUG: Add decode_coords kwarg to backend entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Apr 1, 2024
1 parent 8a0b98d commit 53b3b41
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions rioxarray/xarray_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ def open_dataset(
variable=None,
group=None,
default_name="band_data",
decode_coords="all",
decode_times=True,
decode_timedelta=None,
band_as_variable=False,
open_kwargs=None,
):
if decode_coords != "all":
raise RioXarrayError("Only 'all' is supported for 'decode_coords'.")
if open_kwargs is None:
open_kwargs = {}
rds = _io.open_rasterio(
Expand Down
5 changes: 2 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from functools import partial

import pytest
import rasterio
Expand Down Expand Up @@ -102,9 +103,7 @@ def _assert_xarrays_equal(
assert unwanted_attr not in input_xarray.attrs


def open_rasterio_engine(file_name_or_object, **kwargs):
xarray = pytest.importorskip("xarray", minversion="0.18")
return xarray.open_dataset(file_name_or_object, engine="rasterio", **kwargs)
open_rasterio_engine = partial(xarray.open_dataset, engine="rasterio")


@pytest.fixture(
Expand Down
18 changes: 11 additions & 7 deletions test/integration/test_integration_xarray_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
xarray = pytest.importorskip("xarray", minversion="0.18")


def test_xarray_open_dataset():
@pytest.mark.parametrize(
"kwargs", [{}, {"engine": "rasterio"}, {"decode_coords": "all"}]
)
def test_xarray_open_dataset(kwargs):
cog_file = os.path.join(TEST_INPUT_DATA_DIR, "cog.tif")

ds = xarray.open_dataset(cog_file, engine="rasterio")
ds = xarray.open_dataset(cog_file, **kwargs)

assert isinstance(ds, xarray.Dataset)
assert "band_data" in ds.data_vars
Expand All @@ -22,10 +24,6 @@ def test_xarray_open_dataset():
assert "grid_mapping" in ds.data_vars["band_data"].encoding
assert "preferred_chunks" in ds.data_vars["band_data"].encoding

ds = xarray.open_dataset(cog_file)

assert isinstance(ds, xarray.Dataset)


def test_xarray_open_dataset__drop_variables():
input_file = os.path.join(
Expand Down Expand Up @@ -66,3 +64,9 @@ def test_open_multiple_resolution():
engine="rasterio",
drop_variables="QC_500m_1",
)


def test_xarray_open_dataset__invalid_decode_coords():
cog_file = os.path.join(TEST_INPUT_DATA_DIR, "cog.tif")
with pytest.raises(RioXarrayError):
xarray.open_dataset(cog_file, decode_coords=False)

0 comments on commit 53b3b41

Please sign in to comment.