Skip to content

scan_grib cannot handle GRIB attributes that are arrays #518

Open

Description

@juntyr

... since zarr doesn't support attributes that are not JSON-serializable (including numpy arrays). This can be fixed like this (I don't have time to submit a PR myself right now):

diff --git a/kerchunk/grib2.py b/kerchunk/grib2.py
index e3a927b..0aa2ee6 100644
--- a/kerchunk/grib2.py
+++ b/kerchunk/grib2.py
@@ -103,7 +104,10 @@ def _store_array(store, z, data, var, inline_threshold, offset, size, attr):
             overwrite=True,
         )
         store[f"{var}/" + ".".join(["0"] * len(shape))] = ["{{u}}", offset, size]
-    d.attrs.update(attr)
+    d.attrs.update({
+        k: v.tolist() if isinstance(v, np.ndarray) else v
+        for k, v in attr.items()
+    })
 
 
 def scan_grib(

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions