Skip to content

Commit

Permalink
QA
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyCMWF committed Jun 21, 2024
1 parent 44c7a86 commit e325b4f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/test_50_xarray_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def test_xr_open_dataset_file() -> None:
assert list(ds.data_vars) == ["skt"]


def test_xr_open_dataset_file_ignore_keys() -> None:
ds = xr.open_dataset(TEST_DATA, engine="cfgrib")
assert "GRIB_typeOfLevel" in ds["skt"].attrs
ds = xr.open_dataset(TEST_DATA, engine="cfgrib", ignore_keys=["typeOfLevel"])
assert "GRIB_typeOfLevel" not in ds["skt"].attrs


def test_xr_open_dataset_dict() -> None:
fieldset = {
-10: {
Expand All @@ -49,6 +56,26 @@ def test_xr_open_dataset_dict() -> None:
assert list(ds.data_vars) == ["2t"]


def test_xr_open_dataset_dict_ignore_keys() -> None:
fieldset = {
-10: {
"gridType": "regular_ll",
"Nx": 2,
"Ny": 3,
"distinctLatitudes": [-10.0, 0.0, 10.0],
"distinctLongitudes": [0.0, 10.0],
"paramId": 167,
"shortName": "2t",
"typeOfLevel": "surface",
"values": [[1, 2], [3, 4], [5, 6]],
}
}
ds = xr.open_dataset(fieldset, engine="cfgrib")
assert "GRIB_typeOfLevel" in ds["2t"].attrs
ds = xr.open_dataset(fieldset, engine="cfgrib", ignore_keys=["typeOfLevel"])
assert "GRIB_typeOfLevel" not in ds["2t"].attrs


def test_xr_open_dataset_list() -> None:
fieldset = [
{
Expand All @@ -73,6 +100,27 @@ def test_xr_open_dataset_list() -> None:
assert ds_empty.equals(xr.Dataset())


def test_xr_open_dataset_list_ignore_keys() -> None:
fieldset = [
{
"gridType": "regular_ll",
"Nx": 2,
"Ny": 3,
"distinctLatitudes": [-10.0, 0.0, 10.0],
"distinctLongitudes": [0.0, 10.0],
"paramId": 167,
"shortName": "2t",
"typeOfLevel": "surface",
"values": [[1, 2], [3, 4], [5, 6]],
}
]

ds = xr.open_dataset(fieldset, engine="cfgrib")
assert "GRIB_typeOfLevel" in ds["2t"].attrs
ds = xr.open_dataset(fieldset, engine="cfgrib", ignore_keys=["typeOfLevel"])
assert "GRIB_typeOfLevel" not in ds["2t"].attrs


def test_read() -> None:
expected = {
"latitude": 37,
Expand Down

0 comments on commit e325b4f

Please sign in to comment.