Skip to content

Commit dc07691

Browse files
authored
Merge pull request #123 from intake/fix_122
fix `xarray_image` `to_zarr` if `xr.DataArray`
2 parents 963a5be + dbdf0f1 commit dc07691

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

intake_xarray/tests/test_image.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,14 @@ def test_read_images_and_exif_as_glob_with_coerce():
184184
ds = source.read()
185185
assert ds['raster'].shape == (3, 256, 256, 3)
186186
assert ds['EXIF Image ImageWidth'].shape == (3,)
187+
188+
189+
def test_read_images_and_persist():
190+
pytest.importorskip('skimage')
191+
urlpath = os.path.join(here, 'data', 'images', '*')
192+
source = ImageSource(urlpath=urlpath, coerce_shape=(256, 256))
193+
import tempfile
194+
exported = tempfile.mkdtemp()
195+
source.export(exported)
196+
import xarray as xr
197+
assert xr.open_dataset(exported, engine="zarr")

intake_xarray/xarray_container.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import itertools
22
import os
3+
import xarray as xr
34
from dask.delayed import Delayed
45
from intake.container.base import RemoteSource, get_partition
56
from intake.source.base import Schema
@@ -155,6 +156,9 @@ def _persist(source, path, **kwargs):
155156
http://xarray.pydata.org/en/stable/generated/xarray.Dataset.to_zarr.html
156157
"""
157158
from intake_xarray import ZarrSource
158-
source.to_dask().to_zarr(path, **kwargs)
159+
ds = source.to_dask()
160+
if isinstance(ds, xr.DataArray):
161+
ds = ds.to_dataset(name=ds.name if ds.name else "variable")
162+
ds.to_zarr(path, **kwargs)
159163
return ZarrSource(path)
160164

0 commit comments

Comments
 (0)