zarr-python icon indicating copy to clipboard operation
zarr-python copied to clipboard

Allow passing `shards` to `zarr.zeros`

Open dstansby opened this issue 2 months ago • 1 comments

zarr.zeros (and possibly other convenience functions) doesn't allow specifying shards; it would be nice if this was possible.

import zarr

zarr.zeros(shape=(10,), chunks=(2,), shards=(4,))
Traceback (most recent call last):
  File "/Users/dstansby/software/zarr/zarr-python/test.py", line 3, in <module>
    zarr.zeros(shape=(10,), chunks=(2,), shards=(4,))
  File "/Users/dstansby/software/zarr/zarr-python/src/zarr/api/synchronous.py", line 1441, in zeros
    return Array(sync(async_api.zeros(shape=shape, **kwargs)))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dstansby/software/zarr/zarr-python/src/zarr/core/sync.py", line 159, in sync
    raise return_result
  File "/Users/dstansby/software/zarr/zarr-python/src/zarr/core/sync.py", line 119, in _runner
    return await coro
           ^^^^^^^^^^
  File "/Users/dstansby/software/zarr/zarr-python/src/zarr/api/asynchronous.py", line 1353, in zeros
    return await create(shape=shape, fill_value=0, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dstansby/software/zarr/zarr-python/src/zarr/api/asynchronous.py", line 1087, in create
    return await AsyncArray._create(
                 ^^^^^^^^^^^^^^^^^^^
TypeError: AsyncArray._create() got an unexpected keyword argument 'shards'

dstansby avatar Nov 06 '25 10:11 dstansby

looks like these methods need to target create_array instead of create

d-v-b avatar Nov 06 '25 10:11 d-v-b