The following code works with zarr 2.3.2, but not with more-recently-released versions of zarr (tested on zarr 2.4.0 and zarr 2.6.1). It now gives a TypeError as a result of attempting to JSON serialize a NumPy integer.
importnumpyasnpimportzarrzarr.zeros((10,), chunks=(np.int64(2),))
With zarr 2.3.2, this creates a new array, as expected. With later versions of zarr, I get the following traceback (here with zarr 2.6.1):
(seismic-zarr) mdickinson@mirzakhanitemp%pythonbug.pyTraceback (mostrecentcalllast):
File"bug.py", line4, in<module>zarr.zeros((10,), chunks=(np.int64(2),))
File"/Users/mdickinson/.venvs/seismic-zarr/lib/python3.8/site-packages/zarr/creation.py", line248, inzerosreturncreate(shape=shape, fill_value=0, **kwargs)
File"/Users/mdickinson/.venvs/seismic-zarr/lib/python3.8/site-packages/zarr/creation.py", line121, increateinit_array(store, shape=shape, chunks=chunks, dtype=dtype, compressor=compressor,
File"/Users/mdickinson/.venvs/seismic-zarr/lib/python3.8/site-packages/zarr/storage.py", line344, ininit_array_init_array_metadata(store, shape=shape, chunks=chunks, dtype=dtype,
File"/Users/mdickinson/.venvs/seismic-zarr/lib/python3.8/site-packages/zarr/storage.py", line434, in_init_array_metadatastore[key] =encode_array_metadata(meta)
File"/Users/mdickinson/.venvs/seismic-zarr/lib/python3.8/site-packages/zarr/meta.py", line75, inencode_array_metadatareturnjson_dumps(meta)
File"/Users/mdickinson/.venvs/seismic-zarr/lib/python3.8/site-packages/zarr/util.py", line25, injson_dumpsreturnjson.dumps(o, indent=4, sort_keys=True, ensure_ascii=True,
File"/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line234, indumpsreturncls(
File"/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line201, inencodechunks=list(chunks)
File"/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line431, in_iterencodeyieldfrom_iterencode_dict(o, _current_indent_level)
File"/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line405, in_iterencode_dictyieldfromchunksFile"/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line325, in_iterencode_listyieldfromchunksFile"/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line438, in_iterencodeo=_default(o)
File"/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line179, indefaultraiseTypeError(f'Object of type {o.__class__.__name__} 'TypeError: Objectof type int64isnotJSONserializableThis caused a regression in some other code using zarr: tests started failing after updating zarr.
Please provide the following:
- Value of
zarr.__version__: 2.6.1 - Value of
numcodecs.__version__: 0.7.3 - Version of Python interpreter: 3.8.7 (from MacPorts)
- Operating system (Linux/Windows/Mac): macOS 10.15.7 (Catalina)
- How Zarr was installed (e.g., "using pip into virtual environment", or "using conda"): using pip into a venv.
NumPy version: 1.20.0 (but I was also able to reproduce with NumPy 1.16.5).
The following code works with zarr 2.3.2, but not with more-recently-released versions of zarr (tested on zarr 2.4.0 and zarr 2.6.1). It now gives a
TypeErroras a result of attempting to JSON serialize a NumPy integer.With zarr 2.3.2, this creates a new array, as expected. With later versions of zarr, I get the following traceback (here with zarr 2.6.1):
This caused a regression in some other code using zarr: tests started failing after updating zarr.
Please provide the following:
zarr.__version__: 2.6.1numcodecs.__version__: 0.7.3NumPy version: 1.20.0 (but I was also able to reproduce with NumPy 1.16.5).