-
-
Notifications
You must be signed in to change notification settings - Fork 301
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
User attributes not being saved to file #2079
Comments
I think this is actually the expected behavior. Without import numpy as np
import zarr
arr = zarr.ones((512, 512, 512), dtype=np.uint8, chunks=256)
arr.attrs["attr"] = "value"
print(arr.store[".zattrs"])
# b'{\n "attr": "value"\n}' But |
🤔 so how do I save the attributes to disk? |
When you create an array, you need to associate a store (the default, as you have shown, uses a memory store). This works 👇 import numpy as np
import zarr
arr = zarr.ones((512, 512, 512), dtype=np.uint8, chunks=256, store="test_attr_arr.zarr")
arr.attrs["attr"] = "value" |
Going to take the ❤️ as permission to close this. Feel free to reopen if you run into more gotchas! (btw, you'll be able to do this all in one call in v3: arr = zarr.ones(
shape=(512, 512, 512),
dtype=np.uint8,
chunks=256,
store="test_attr_arr.zarr",
attributes={"attr": "value"}
) |
What I really want to do is work with an array in memory (including adding some attributes), and then save it in one go to disk. So I think it's worth at least documenting how to do that workflow somewhere? |
I think this would be equivalent to copying the memory store to a directory store. Is there not a |
Yep, there is a copy_store function. Clearly my mental model of how zarr (or at least |
a few thoughts about this flow:
|
This issue made me think about array creation routines, I wrote up some ideas here: #2083 |
Zarr version
2.18.2
Numcodecs version
0.12.1
Python Version
3.11
Operating System
macOS
Installation
conda
Description
I'm trying to save user attributes to file, but they don't seem to be saved when calling
zarr.save_array
.Steps to reproduce
The resulting zarr array on disk does not have a
.zattrs
file as I would expect.Additional output
No response
The text was updated successfully, but these errors were encountered: