我正在尝试整合现有 zarr 商店的元数据,但如果我创建新的 zarr 商店并调用zarr.consolidate_metadata(store)
.
代码示例:
import zarr
## create test zarr store
path_to_store = "test.zarr"
store = zarr.open(path_to_store)
store.create_dataset('foo', shape=(10000, 10000), chunks=(1000, 1000), dtype='i4')
## call consolidate_metadata on store
zarr.consolidate_metadata(store)
这将创建一个.zmetadata
目录,而不是文件,其中包含一个 0 块,就像它是一个 zarr 数组。但是调用本身会出错TypeError: memoryview: a bytes-like object is required, not 'Array'
。
我认为它创建这个.zmetadata
数组可能是 zarr 中的一个错误,但是我尝试了不同的 zarr 和 Python 版本,所以我很确定我也做错了,因为这样一个主要错误不会持续很长时间。
完整的错误是:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/var/folders/xf/xwjm3rj52ls9780rvrbbb9tm0000gn/T/ipykernel_84668/2011535042.py in <module>
1 ## call consolidate_metadata on store
----> 2 zarr.consolidate_metadata(store)
/opt/anaconda3/envs/gefs/lib/python3.9/site-packages/zarr/convenience.py in consolidate_metadata(store, metadata_key)
1122 }
1123 store[metadata_key] = json_dumps(out)
-> 1124 return open_consolidated(store, metadata_key=metadata_key)
1125
1126
/opt/anaconda3/envs/gefs/lib/python3.9/site-packages/zarr/convenience.py in open_consolidated(store, metadata_key, mode, **kwargs)
1176
1177 # setup metadata store
-> 1178 meta_store = ConsolidatedMetadataStore(store, metadata_key=metadata_key)
1179
1180 # pass through
/opt/anaconda3/envs/gefs/lib/python3.9/site-packages/zarr/storage.py in __init__(self, store, metadata_key)
2767
2768 # retrieve consolidated metadata
-> 2769 meta = json_loads(store[metadata_key])
2770
2771 # check format of consolidated metadata
/opt/anaconda3/envs/gefs/lib/python3.9/site-packages/zarr/util.py in json_loads(s)
33 def json_loads(s: str) -> Dict[str, Any]:
34 """Read JSON in a consistent way."""
---> 35 return json.loads(ensure_text(s, 'ascii'))
36
37
/opt/anaconda3/envs/gefs/lib/python3.9/site-packages/numcodecs/compat.py in ensure_text(s, encoding)
126 def ensure_text(s, encoding='utf-8'):
127 if not isinstance(s, str):
--> 128 s = ensure_contiguous_ndarray(s)
129 s = codecs.decode(s, encoding)
130 return s
/opt/anaconda3/envs/gefs/lib/python3.9/site-packages/numcodecs/compat.py in ensure_contiguous_ndarray(buf, max_buffer_size)
79
80 # ensure input is a numpy array
---> 81 arr = ensure_ndarray(buf)
82
83 # check for object arrays, these are just memory pointers, actual memory holding
/opt/anaconda3/envs/gefs/lib/python3.9/site-packages/numcodecs/compat.py in ensure_ndarray(buf)
43 # N.B., first take a memoryview to make sure that we subsequently create a
44 # numpy array from a memory buffer with no copy
---> 45 mem = memoryview(buf)
46
47 # instantiate array from memoryview, ensures no copy
TypeError: memoryview: a bytes-like object is required, not 'Array'