Skip to content

Commit

Permalink
Fix FieldCube crash when generating detailed error report (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandorkertesz authored Sep 17, 2024
1 parent 5fc1e6a commit 60cfad3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/release_notes/version_0.10_updates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Version 0.10 Updates
/////////////////////////


Version 0.10.3
===============

Fixes
++++++

- Fixed issue when building a FieldCube crashed while generating error message due to missing "number" metadata key in input GRIB data (:pr:`456`).


Version 0.10.2
===============

Expand Down
4 changes: 2 additions & 2 deletions src/earthkit/data/indexing/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(
# print(self.source[3])

# Get a mapping of user names to unique values
# With possible reduce dimentionality if the user use 'level+param'
# With possible reduce dimensionality if the user use 'level+param'
self.user_coords = self.source.unique_values(*names, remapping=remapping, patches=patches)

self.user_shape = tuple(len(v) for k, v in self.user_coords.items())
Expand All @@ -98,7 +98,7 @@ def __init__(
details.append(f"{key=} ({len(v)}) {v}")
assert not isinstance(self.source, str), f"Not expecting a str here ({self.source})"
for i, f in enumerate(self.source):
details.append(f"{i}={f} {f.metadata('number')}")
details.append(f"{i}={f} {f.metadata('number', default=None)}")
if i > 30:
details.append("...")
break
Expand Down
11 changes: 11 additions & 0 deletions tests/grib/test_grib_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#

import numpy as np
import pytest

from earthkit.data import from_source
from earthkit.data.testing import earthkit_examples_file
from earthkit.data.testing import earthkit_test_data_file


def test_grib_cube():
Expand Down Expand Up @@ -124,6 +126,15 @@ def test_grib_cubelet():
assert np.isclose(cb.to_numpy()[0, 0], ref[i])


def test_grib_cube_non_hypercube():
ds = from_source("file", earthkit_examples_file("tuv_pl.grib"))
ds += from_source("file", earthkit_test_data_file("ml_data.grib"))[:2]
assert len(ds) == 18 + 2

with pytest.raises(ValueError):
ds.cube("param", "level")


if __name__ == "__main__":
from earthkit.data.testing import main

Expand Down

0 comments on commit 60cfad3

Please sign in to comment.