Skip to content

Commit 5d77292

Browse files
authored
Merge pull request #651 from joshmoore/n5-attrs
2 parents 859b1db + 3272ba4 commit 5d77292

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

zarr/n5.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,18 @@ def invert_chunk_coords(key):
304304
def group_metadata_to_n5(group_metadata):
305305
'''Convert group metadata from zarr to N5 format.'''
306306
del group_metadata['zarr_format']
307+
# TODO: This should only exist at the top-level
307308
group_metadata['n5'] = '2.0.0'
308309
return group_metadata
309310

310311

311312
def group_metadata_to_zarr(group_metadata):
312313
'''Convert group metadata from N5 to zarr format.'''
313-
del group_metadata['n5']
314+
try:
315+
group_metadata.pop('n5')
316+
except KeyError:
317+
# This only exists at the top level
318+
pass
314319
group_metadata['zarr_format'] = ZARR_FORMAT
315320
return group_metadata
316321

zarr/tests/test_creation.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,24 @@ def test_open_array():
252252
assert (10,) == z.chunks
253253
assert_array_equal(np.full(100, fill_value=42), z[:])
254254

255+
store = 'data/group.n5'
256+
z = open_group(store, mode='w')
257+
i = z.create_group('inner')
258+
a = i.zeros("array", shape=100, chunks=10)
259+
a[:] = 42
260+
261+
# Edit inner/attributes.json to not include "n5"
262+
with open('data/group.n5/inner/attributes.json', 'w') as o:
263+
o.write("{}")
264+
265+
# Re-open
266+
a = open_group(store)["inner"]["array"]
267+
assert isinstance(a, Array)
268+
assert isinstance(z.store, N5Store)
269+
assert (100,) == a.shape
270+
assert (10,) == a.chunks
271+
assert_array_equal(np.full(100, fill_value=42), a[:])
272+
255273

256274
def test_empty_like():
257275

0 commit comments

Comments
 (0)