kerchunk icon indicating copy to clipboard operation
kerchunk copied to clipboard

scan_grib cannot handle GRIB attributes that are arrays

Open juntyr opened this issue 1 year ago • 0 comments

... 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(

juntyr avatar Oct 21 '24 06:10 juntyr