Skip to content

Commit dff7cb8

Browse files
committed
Handle case where reading of scalar masked value from netCDF file
looses the original dtype.
1 parent c3fa75c commit dff7cb8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/iris/fileformats/netcdf/loader.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ def _get_cf_var_data(cf_var, filename):
253253
if total_bytes < _LAZYVAR_MIN_BYTES:
254254
# Don't make a lazy array, as it will cost more memory AND more time to access.
255255
result = cf_var[:]
256+
257+
# Special handling of masked scalar value; this will be returned as
258+
# an `np.ma.masked` instance which will loose the original dtype.
259+
# Workaround for this it return a 1-element masked array of the
260+
# correct dtype. Note - this is not an ussue for masked arrays,
261+
# only masked scalar values.
262+
if result is np.ma.masked:
263+
result = np.ma.masked_all(1, dtype=cf_var.datatype)
256264
else:
257265
# Get lazy chunked data out of a cf variable.
258266
# Creates Dask wrappers around data arrays for any cube components which

0 commit comments

Comments
 (0)