Skip to content

Commit c18537d

Browse files
authored
Allow chunk_store argument in open_consolidated() (#557)
1 parent 1569ec1 commit c18537d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

zarr/convenience.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,4 +1179,5 @@ def open_consolidated(store, metadata_key='.zmetadata', mode='r+', **kwargs):
11791179
meta_store = ConsolidatedMetadataStore(store, metadata_key=metadata_key)
11801180

11811181
# pass through
1182-
return open(store=meta_store, chunk_store=store, mode=mode, **kwargs)
1182+
chunk_store = kwargs.pop('chunk_store', None) or store
1183+
return open(store=meta_store, chunk_store=chunk_store, mode=mode, **kwargs)

zarr/tests/test_convenience.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,56 @@ def test_consolidate_metadata():
165165
open_consolidated(store, cache_attrs=True, synchronizer=None)
166166

167167

168+
def test_consolidated_with_chunk_store():
169+
# setup initial data
170+
store = MemoryStore()
171+
chunk_store = MemoryStore()
172+
z = group(store, chunk_store=chunk_store)
173+
z.create_group('g1')
174+
g2 = z.create_group('g2')
175+
g2.attrs['hello'] = 'world'
176+
arr = g2.create_dataset('arr', shape=(20, 20), chunks=(5, 5), dtype='f8')
177+
assert 16 == arr.nchunks
178+
assert 0 == arr.nchunks_initialized
179+
arr.attrs['data'] = 1
180+
arr[:] = 1.0
181+
assert 16 == arr.nchunks_initialized
182+
183+
# perform consolidation
184+
out = consolidate_metadata(store)
185+
assert isinstance(out, Group)
186+
assert '.zmetadata' in store
187+
for key in ['.zgroup',
188+
'g1/.zgroup',
189+
'g2/.zgroup',
190+
'g2/.zattrs',
191+
'g2/arr/.zarray',
192+
'g2/arr/.zattrs']:
193+
del store[key]
194+
# open consolidated
195+
z2 = open_consolidated(store, chunk_store=chunk_store)
196+
assert ['g1', 'g2'] == list(z2)
197+
assert 'world' == z2.g2.attrs['hello']
198+
assert 1 == z2.g2.arr.attrs['data']
199+
assert (z2.g2.arr[:] == 1.0).all()
200+
assert 16 == z2.g2.arr.nchunks
201+
assert 16 == z2.g2.arr.nchunks_initialized
202+
203+
# test the data are writeable
204+
z2.g2.arr[:] = 2
205+
assert (z2.g2.arr[:] == 2).all()
206+
207+
# test invalid modes
208+
with pytest.raises(ValueError):
209+
open_consolidated(store, mode='a', chunk_store=chunk_store)
210+
with pytest.raises(ValueError):
211+
open_consolidated(store, mode='w', chunk_store=chunk_store)
212+
213+
# make sure keyword arguments are passed through without error
214+
open_consolidated(store, cache_attrs=True, synchronizer=None,
215+
chunk_store=chunk_store)
216+
217+
168218
class TestCopyStore(unittest.TestCase):
169219

170220
def setUp(self):

0 commit comments

Comments
 (0)