Skip to content

Commit

Permalink
Merge pull request #401 from ecmwf/fix/validate_attrs
Browse files Browse the repository at this point in the history
Update call to xarray _validate_attrs
  • Loading branch information
iainrussell authored Sep 12, 2024
2 parents 454510e + 51425cf commit 18724ec
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cfgrib/xarray_to_grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ def canonical_dataset_to_grib(dataset, path, mode="wb", no_warn=False, grib_keys

# validate Dataset keys, DataArray names, and attr keys/values
xr.backends.api._validate_dataset_names(dataset) # type: ignore
xr.backends.api._validate_attrs(dataset) # type: ignore
# _validate_attrs takes the engine name as its 2nd arg from xarray 2024.09.0
try:
xr.backends.api._validate_attrs(dataset) # type: ignore
except TypeError:
xr.backends.api._validate_attrs(dataset, "cfgrib") # type: ignore

real_grib_keys = {str(k)[5:]: v for k, v in dataset.attrs.items() if str(k)[:5] == "GRIB_"}
real_grib_keys.update(grib_keys)
Expand Down

0 comments on commit 18724ec

Please sign in to comment.