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 failing grib metadata tests #231

Merged
merged 1 commit into from
Oct 16, 2023
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
6 changes: 6 additions & 0 deletions earthkit/data/readers/grib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ class RestrictedGribMetadata(GribMetadata):

EKD_NAMESPACE = "grib"
INTERNAL_KEYS = [
"minimum",
"maximum",
"average",
"standardDeviation",
"skewness",
"kurtosis",
"min",
"max",
"avg",
Expand Down
19 changes: 11 additions & 8 deletions tests/core/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,22 @@ def test_grib_metadata_get():
ds = from_source("file", earthkit_examples_file("test.grib"))
md = ds[0].metadata()

assert len(md) == 192
# the number/order of metadata keys can vary with the ecCodes version
md_num = len(md)
assert md_num > 100

keys = list(md.keys())
assert len(keys) == 192
assert keys[0] == "globalDomain"
assert keys[10] == "wrongPadding"
assert len(keys) == md_num
assert "shortName" in keys
assert "maximum" in keys

keys = [k for k in md]
assert len(keys) == 192
assert keys[0] == "globalDomain"
assert keys[10] == "wrongPadding"
assert len(keys) == md_num
assert "shortName" in keys
assert "maximum" in keys

items = {k: v for k, v in md.items()}
assert len(items) == 192
assert len(items) == md_num
assert items["shortName"] == "2t"
assert items["typeOfLevel"] == "surface"

Expand Down
12 changes: 8 additions & 4 deletions tests/grib/test_grib_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,27 +421,31 @@ def test_grib_metadata_namespace(mode):
}
assert r == ref

# The number/order of metadata keys can vary with the ecCodes version.
# The same is true for the namespaces.

r = f[0].metadata(namespace=None)
assert isinstance(r, dict)
assert len(r) == 186
md_num = len(r)
assert md_num > 100
assert r["level"] == 1000
assert r["stepType"] == "instant"

r = f[0].metadata(namespace=[None])
assert isinstance(r, dict)
assert len(r) == 186
assert len(r) == md_num
assert r["level"] == 1000
assert r["stepType"] == "instant"

r = f[0].metadata(namespace="")
assert isinstance(r, dict)
assert len(r) == 186
assert len(r) == md_num
assert r["level"] == 1000
assert r["stepType"] == "instant"

r = f[0].metadata(namespace=[""])
assert isinstance(r, dict)
assert len(r) == 186
assert len(r) == md_num
assert r["level"] == 1000
assert r["stepType"] == "instant"

Expand Down
24 changes: 16 additions & 8 deletions tests/numpy_fs/test_numpy_fs_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,23 @@ def test_numpy_fs_values_metadata_internal():
def test_numpy_fs_metadata_keys():
ds, _ = load_numpy_fs(1)

num = 183
# The number/order of metadata keys can vary with the ecCodes version.
# The same is true for the namespaces.

md = ds[0].metadata()
assert len(md) == num
md_num = len(md)
assert md_num > 100

keys = md.keys()
assert len(keys) == num
assert len(keys) == md_num

for k in md.keys():
assert isinstance(k, str)
assert k != ""
break

items = md.items()
assert len(items) == num
assert len(items) == md_num

for k, v in md.items():
assert isinstance(k, str)
Expand All @@ -90,6 +93,7 @@ def test_numpy_fs_metadata_keys():
break

assert "max" not in md
assert "maximum" not in md
assert "statistics.max" not in md
assert "validityDate" in md

Expand Down Expand Up @@ -118,27 +122,31 @@ def test_numpy_fs_metadata_namespace():
}
assert r == ref

# The number/order of metadata keys can vary with the ecCodes version.
# The same is true for the namespaces.

r = f[0].metadata(namespace=None)
assert isinstance(r, dict)
assert len(r) == 177
md_num = len(r)
assert md_num > 100
assert r["level"] == 1000
assert r["stepType"] == "instant"

r = f[0].metadata(namespace=[None])
assert isinstance(r, dict)
assert len(r) == 177
assert len(r) == md_num
assert r["level"] == 1000
assert r["stepType"] == "instant"

r = f[0].metadata(namespace="")
assert isinstance(r, dict)
assert len(r) == 177
assert len(r) == md_num
assert r["level"] == 1000
assert r["stepType"] == "instant"

r = f[0].metadata(namespace=[""])
assert isinstance(r, dict)
assert len(r) == 177
assert len(r) == md_num
assert r["level"] == 1000
assert r["stepType"] == "instant"

Expand Down
Loading