Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FieldCube crash when generating detailed error report #458

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading