Problem description
When using open_consolidated on stores that we were created without consolidating the metadata, the user gets a KeyError. I think for folks familiar with zarr, it's easy to diagnose what's going on. However, for new users, the error can be too cryptic (especially when using xarray which exposes zarr.open_consolidated() via a consolidated keyword argument).
I'm wondering if it would be reasonable (if feasible) to provide a more informative error. I am imagining something along these lines:
FileNotFoundError: Couldn't find consolidated metadata file: '.zmetadata'. Tryopeningthestorewith`zarr.open(...)`
instead of
I don't know if my suggestion is generic enough to warrant a change in zarr. I'm happy to bring up the issue upstream in xarray.
Minimal, reproducible code sample, a copy-pastable example if possible
In [43]: importzarrIn [44]: importnumpyasnpIn [45]: store=zarr.DirectoryStore("dataset.zarr")
In [46]: ds=zarr.array(np.arange(10))
In [47]: zarr.save(store, ds)
In [48]: zarr.open(store)
Out[48]: <zarr.core.Array (10,) int64>In [49]: zarr.open_consolidated(store)
---------------------------------------------------------------------------KeyErrorTraceback (mostrecentcalllast)
<ipython-input-49-f77b4b56ec4c>in<module>---->1zarr.open_consolidated(store)
/glade/work/abanihi/opt/miniconda/envs/playground/lib/python3.8/site-packages/zarr/convenience.pyinopen_consolidated(store, metadata_key, mode, **kwargs)
11761177# setup metadata store->1178meta_store=ConsolidatedMetadataStore(store, metadata_key=metadata_key)
11791180# pass through/glade/work/abanihi/opt/miniconda/envs/playground/lib/python3.8/site-packages/zarr/storage.pyin__init__(self, store, metadata_key)
27672768# retrieve consolidated metadata->2769meta=json_loads(store[metadata_key])
27702771# check format of consolidated metadata/glade/work/abanihi/opt/miniconda/envs/playground/lib/python3.8/site-packages/zarr/storage.pyin__getitem__(self, key)
844returnself._fromfile(filepath)
845else:
-->846raiseKeyError(key)
847848def__setitem__(self, key, value):
KeyError: '.zmetadata'
Version and installation information
Please provide the following:
- Value of
zarr.__version__: 2.8.3 - Value of
numcodecs.__version__: 0.7.3 - Version of Python interpreter: 3.8.8
- Operating system: Linux
- How Zarr was installed: conda
Problem description
When using
open_consolidatedon stores that we were created without consolidating the metadata, the user gets aKeyError. I think for folks familiar with zarr, it's easy to diagnose what's going on. However, for new users, the error can be too cryptic (especially when using xarray which exposeszarr.open_consolidated()via aconsolidatedkeyword argument).I'm wondering if it would be reasonable (if feasible) to provide a more informative error. I am imagining something along these lines:
instead of
I don't know if my suggestion is generic enough to warrant a change in zarr. I'm happy to bring up the issue upstream in xarray.
Minimal, reproducible code sample, a copy-pastable example if possible
Version and installation information
Please provide the following:
zarr.__version__: 2.8.3numcodecs.__version__: 0.7.3