Skip to content

Commit

Permalink
Handle numpy chunk encoding, Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Apr 10, 2024
1 parent 39b4244 commit 3b7dd45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 3 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ def test_invalid_encoding_chunks_with_dask_raise():
excinfo.match(r'Specified zarr chunks .*')


def test_invalid_encoding_chunks_with_numpy_raise():
def test_ignore_encoding_chunks_with_numpy():
data = np.zeros((10, 20, 30))
ds = xr.Dataset({'foo': (['x', 'y', 'z'], data)})
ds['foo'].encoding['chunks'] = [8, 5, 1]
with pytest.raises(ValueError) as excinfo:
_ = create_zmetadata(ds)
excinfo.match(r'Encoding chunks do not match inferred.*')
zmetadata = create_zmetadata(ds)
assert zmetadata['metadata']['foo/.zarray']['chunks'] == [10, 20, 30]


def test_get_data_chunk_numpy():
Expand Down
3 changes: 2 additions & 1 deletion xpublish/utils/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ def _extract_zarray(
if meta['chunks'] is None:
meta['chunks'] = da.shape

# validate chunks
# validate chunks for dask arrays, numpy arrays match the encoding to the shape
if isinstance(da.data, DaskArrayType):
var_chunks = tuple([c[0] for c in da.data.chunks])
else:
var_chunks = da.shape
meta['chunks'] = da.shape
if not var_chunks == tuple(meta['chunks']):
raise ValueError('Encoding chunks do not match inferred chunks')

Expand Down

0 comments on commit 3b7dd45

Please sign in to comment.