Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_empty_chunks and zarr.zeros #2060

Closed
AlexHenderson opened this issue Jul 31, 2024 · 2 comments
Closed

write_empty_chunks and zarr.zeros #2060

AlexHenderson opened this issue Jul 31, 2024 · 2 comments
Labels
V2 Affects the v2 branch

Comments

@AlexHenderson
Copy link

Hi,

The example here https://zarr.readthedocs.io/en/stable/tutorial.html#empty-chunks for not writing empty chunks works fine. However, if I use zarr.zeros rather than zarr.open, empty chunks are still written to file.

import zarr
arr = zarr.zeros((10000, 10000), chunks=(1000, 1000), dtype='i4', write_empty_chunks=False)
zarr.save("./testlocation", arr)

./testlocation now contains 101 files although fill_type is 0 by default in zarr.zeros.

zarr.version = 2.18.2
python 3.12.4
installation via poetry

Not sure if this is a bug, or I'm doing something wrong.

Thanks,
Alex

@d-v-b
Copy link
Contributor

d-v-b commented Aug 3, 2024

hi @AlexHenderson, try passing write_empty_chunks=False as a keyword argument to zarr.save.

Your code example is actually creating two separate zarr arrays: the first array is created with the zarr.zeros function, and it uses in-memory storage, because that's the default storage backend if none is specified. zarr.save will create a second array on the file system using one of the file system-based storage backends. That second array is a structurally identical copy of the first array, but write_empty_chunks is a runtime detail, it's not part of the array metadata, so that doesn't get automatically copied over when you create the second array.

you can actually skip the invocation of zarr.save by passing a store keyword argument to zarr.zeros, e.g.

arr = zarr.zeros(store='testlocation', path='my_array', (10000, 10000), chunks=(1000, 1000), dtype='i4', write_empty_chunks=False)

@jhamman jhamman added the V2 Affects the v2 branch label Sep 13, 2024
@jhamman
Copy link
Member

jhamman commented Oct 23, 2024

Closing as stale.

xref: #2409

@jhamman jhamman closed this as completed Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 Affects the v2 branch
Projects
None yet
Development

No branches or pull requests

3 participants