Skip to content

attrs cannot store values of type np.int32 or np.bool_ #481

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

Closed
amkigit opened this issue Sep 29, 2019 · 2 comments
Closed

attrs cannot store values of type np.int32 or np.bool_ #481

amkigit opened this issue Sep 29, 2019 · 2 comments

Comments

@amkigit
Copy link

amkigit commented Sep 29, 2019

Hello,

I tried to store some np.int32 or np.bool8 values in the attrs of the root group, but this failed.

Values of type np.float64 work.

Please see the attached example

zerror.txt

@jrbourbeau
Copy link
Member

Thanks for opening an issue @amkigit! I'm able to reproduce an error with your example (pasting here for future reference):

import zarr
import numpy as np

root = zarr.open('zerror', mode='w')

vals=[np.float64(1), np.int32(2), np.bool8(True)]

for i in range(len(vals)):
    try:
        root.attrs[str(i)]=vals[i]
    except:
        print(type(vals[i]))
        val=int(vals[i])
        root.attrs[str(i)]=val

This is a current limitation of Zarr as attributes must be json-serializable. This was previously reported and discussed over in #156. Would it be alright to close this issue as a duplicate and move the conversation over to #156?

@jakirkham
Copy link
Member

Yeah let's close this and consolidate.

As a workaround, @amkigit you may consider converting your data to native JSON types first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants