Skip to content

Commit d7d8815

Browse files
authored
Fix N5Store dtype wrong behavior (#1340)
* create a test case for the bug * fix dtype bug * fix formatting * optimize code by using create function * use at exit delete * optimize import * update n5 test hexdigest * skip dtype decode if no fsspec * add contribution
1 parent c375030 commit d7d8815

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Bug fixes
6161
* NestedDirectoryStore.listdir now returns chunk keys with the correct '/' dimension_separator.
6262
By :user:`Brett Graham <braingram>` :issue:`1334`.
6363

64+
* N5Store/N5FSStore dtype returns zarr Stores readable dtype.
65+
By :user:`Marwan Zouinkhi <mzouink>` :issue:`1339`.
66+
6467
.. _release_2.13.6:
6568

6669
2.13.6

zarr/n5.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ def array_metadata_to_zarr(array_metadata: Dict[str, Any],
689689
array_metadata['order'] = 'C'
690690
array_metadata['filters'] = []
691691
array_metadata['dimension_separator'] = '.'
692+
array_metadata['dtype'] = np.dtype(array_metadata['dtype']).str
692693

693694
compressor_config = array_metadata['compressor']
694695
compressor_config = compressor_config_to_zarr(compressor_config)

zarr/tests/test_core.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,13 +2034,12 @@ def test_compressors(self):
20342034
assert np.all(a2[:] == 1)
20352035

20362036
def expected(self):
2037-
return [
2038-
'4e9cf910000506455f82a70938a272a3fce932e5',
2039-
'f9d4cbf1402901f63dea7acf764d2546e4b6aa38',
2040-
'1d8199f5f7b70d61aa0d29cc375212c3df07d50a',
2041-
'874880f91aa6736825584509144afe6b06b0c05c',
2042-
'e2258fedc74752196a8c8383db49e27193c995e2',
2043-
]
2037+
return ['8811a77d54caaa1901d5cc4452d946ae433c8d90',
2038+
'd880b007d9779db5f2cdbe13274eb1cbac4a425a',
2039+
'd80eb66d5521744f051e816ab368d8ccfc2e3edf',
2040+
'568f9f837e4b682a3819cb122988e2eebeb6572b',
2041+
'4fdf4475d786d6694110db5619acd30c80dfc372'
2042+
]
20442043

20452044

20462045
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")

zarr/tests/test_n5.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
21
import pytest
32

4-
from zarr.n5 import N5ChunkWrapper
3+
from zarr.n5 import N5ChunkWrapper, N5FSStore
4+
from zarr.creation import create
5+
from zarr.storage import atexit_rmtree
56
from numcodecs import GZip
67
import numpy as np
78
from typing import Tuple
9+
import json
10+
import atexit
11+
12+
from zarr.tests.util import have_fsspec
813

914

1015
def test_make_n5_chunk_wrapper():
@@ -35,3 +40,15 @@ def test_partial_chunk_decode(chunk_shape: Tuple[int, ...]):
3540
chunk[subslices] = 1
3641
subchunk = np.ascontiguousarray(chunk[subslices])
3742
assert np.array_equal(codec_wrapped.decode(codec_wrapped.encode(subchunk)), chunk)
43+
44+
45+
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
46+
def test_dtype_decode():
47+
path = 'data/array.n5'
48+
atexit_rmtree(path)
49+
atexit.register(atexit_rmtree, path)
50+
n5_store = N5FSStore(path)
51+
create(100, store=n5_store)
52+
dtype_n5 = json.loads(n5_store[".zarray"])["dtype"]
53+
dtype_zarr = json.loads(create(100).store[".zarray"])["dtype"]
54+
assert dtype_n5 == dtype_zarr

0 commit comments

Comments
 (0)