Skip to content

problem with numpy type error (not serializable) #550

Description

@mdsumner

I see this

from virtualizarr import  open_virtual_dataset
u = 'https://thredds.nci.org.au/thredds/fileServer/gb6/BRAN/BRAN2023/daily/ocean_salt_2024_06.nc'

ds = open_virtual_dataset(u)

ds.virtualize.to_kerchunk('/tmp/test.parquet', format = "parquet")
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
#   File "/VirtualiZarr/virtualizarr/accessor.py", line 137, in to_kerchunk
#     refs = dataset_to_kerchunk_refs(self.ds)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/VirtualiZarr/virtualizarr/writers/kerchunk.py", line 72, in dataset_to_kerchunk_refs
#     ".zattrs": ujson.dumps(attrs),
#                ^^^^^^^^^^^^^^^^^^
# TypeError: np.int32(20) is not JSON serializable


## drop the problem numpy attribute
ds.attrs['NumFilesInSet'] = None
## now it works
ds.virtualize.to_kerchunk('/tmp/test.parquet', format = "parquet")

I wonder if this typing in attributes has a general solution? Appreciate this may be a kerchunk topic

(it takes a few minutes to virtualize from URL I'm afraid, it's a 4.3Gb file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    KerchunkRelating to the kerchunk library / specification itselfbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions