Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opening STAC Assets with xarray:open_kwargs engine field #18

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ def simple_zarr() -> pystac.Asset:
catalog = pystac_client.Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = catalog.get_collection("daymet-daily-hi")
return collection.assets["zarr-abfs"]


@pytest.fixture(scope="module")
def complex_zarr(simple_zarr) -> pystac.Asset:
simple_zarr.extra_fields["xarray:open_kwargs"]["engine"] = "zarr"
return simple_zarr
7 changes: 6 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ def test_to_xarray_reference_file(simple_reference_file):

def test_to_xarray_zarr(simple_zarr):
ds = to_xarray(simple_zarr)
ds
assert ds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!



def test_to_xarray_zarr_with_open_kwargs_engine(complex_zarr):
ds = to_xarray(complex_zarr)
assert ds
2 changes: 1 addition & 1 deletion xpystac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ def _(obj: pystac.Asset, **kwargs) -> xarray.Dataset:
else:
default_kwargs = {}

ds = xarray.open_dataset(obj.href, **default_kwargs, **open_kwargs, **kwargs)
ds = xarray.open_dataset(obj.href, **{**default_kwargs, **open_kwargs, **kwargs})
return ds