Skip to content

How to prevent to_zarr method in xarray from writing all nan chunks to disk? #7451

Answered by rafa-guedes
sh-dot-s asked this question in Q&A
Discussion options

You must be logged in to vote

There is an encoding option write_empty_chunks that can be used for that:

xarr.to_dataset().to_zarr("allchunks.zarr", mode="w")
xarr.to_dataset().to_zarr("somechunks.zarr", mode="w", encoding={"test": {"write_empty_chunks": False}})
$ ls -l allchunks.zarr/test 
total 64K
-rw-rw-r-- 1 rguedes rguedes 212 Jan 18 22:13 0.0
-rw-rw-r-- 1 rguedes rguedes 18K Jan 18 22:13 0.1
-rw-rw-r-- 1 rguedes rguedes 18K Jan 18 22:13 1.0
-rw-rw-r-- 1 rguedes rguedes 18K Jan 18 22:13 1.1
$ ls -l somechunks.zarr/test 
total 60
-rw-rw-r-- 1 rguedes rguedes 17580 Jan 18 22:13 0.1
-rw-rw-r-- 1 rguedes rguedes 17572 Jan 18 22:13 1.0
-rw-rw-r-- 1 rguedes rguedes 17572 Jan 18 22:13 1.1

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sh-dot-s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants