diff --git a/activestorage/active.py b/activestorage/active.py index 7ffe141c..fb963f32 100644 --- a/activestorage/active.py +++ b/activestorage/active.py @@ -114,6 +114,9 @@ def hfix(x): _FillValue = hfix(ds.attrs.get('_FillValue')) missing_value = ds.attrs.get('missing_value') + # see https://github.com/NCAS-CMS/PyActiveStorage/pull/303 + if isinstance(missing_value, np.ndarray): + missing_value = missing_value[0] valid_min = hfix(ds.attrs.get('valid_min')) valid_max = hfix(ds.attrs.get('valid_max')) valid_range = hfix(ds.attrs.get('valid_range')) diff --git a/tests/unit/test_active.py b/tests/unit/test_active.py index 30453e5b..d2f5c600 100644 --- a/tests/unit/test_active.py +++ b/tests/unit/test_active.py @@ -8,7 +8,7 @@ from botocore.exceptions import NoCredentialsError as NoCredsExc from netCDF4 import Dataset -from activestorage.active import Active, load_from_s3 +from activestorage.active import Active, load_from_s3, get_missing_attributes from activestorage.config import * @@ -32,6 +32,13 @@ def test_uri_nonexistent(): assert str(exc.value) == expected +def test_get_missing_attributes(): + """Test get missing attributes.""" + ds = pyfive.File("tests/test_data/cesm2_native.nc")["TREFHT"] + missing_attrs = get_missing_attributes(ds) + assert missing_attrs == (np.float32(-900.0), np.float32(-900.0), None, None) + + def test_getitem(): """Unit test for class:Active.""" # no variable passed