Skip to content

Commit 929b03b

Browse files
committed
added AuxCoord test
1 parent fc8c78b commit 929b03b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/iris/fileformats/netcdf/loader.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,15 @@ def _get_cf_var_data(cf_var, filename):
243243
chunks = cf_var.cf_data.chunking()
244244
# In the "contiguous" case, pass chunks=None to 'as_lazy_data'.
245245
if chunks == "contiguous":
246-
if CHUNK_CONTROL.mode is ChunkControl.Modes.FROM_FILE:
246+
if (
247+
CHUNK_CONTROL.mode is ChunkControl.Modes.FROM_FILE
248+
and isinstance(
249+
cf_var, iris.fileformats.cf.CFDataVariable
250+
)
251+
):
247252
raise KeyError(
248253
f"{cf_var.cf_name} does not contain pre-existing chunk specifications."
249-
f"Instead, you might wish to use CHUNK_CONTROL.set(), or just use default"
254+
f" Instead, you might wish to use CHUNK_CONTROL.set(), or just use default"
250255
f" behaviour outside of a context manager. "
251256
)
252257
# Equivalent to chunks=None, but value required by chunking control

lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
# Import iris.tests first so that some things can be initialised before
88
# importing anything else.
99
import iris.tests as tests # isort:skip
10-
1110
from unittest.mock import ANY, patch
1211

1312
import dask
13+
import numpy as np
1414
import pytest
1515

1616
import iris
@@ -34,7 +34,18 @@ def save_cubelist_with_sigma(tmp_filepath):
3434

3535
@pytest.fixture
3636
def save_cube_with_chunksize(tmp_filepath):
37-
iris.save(istk.simple_3d(), tmp_filepath, chunksizes=(1, 3, 4))
37+
cube = istk.simple_3d()
38+
# adding an aux coord allows us to test that
39+
# iris.fileformats.netcdf.loader._get_cf_var_data()
40+
# will only throw an error if from_file mode is
41+
# True when the entire cube has no specified chunking
42+
aux = iris.coords.AuxCoord(
43+
points=np.zeros((3, 4)),
44+
long_name="random",
45+
units="1",
46+
)
47+
cube.add_aux_coord(aux, [1, 2])
48+
iris.save(cube, tmp_filepath, chunksizes=(1, 3, 4))
3849

3950

4051
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)