Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Loading CellMeasures with non-float values is now supported.
21 changes: 8 additions & 13 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,13 +2077,13 @@ def __init__(self, data, standard_name=None, long_name=None,
Kwargs:

* standard_name:
CF standard name of the coordinate.
CF standard name of the cell measure.
* long_name:
Descriptive name of the coordinate.
Descriptive name of the cell measure.
* var_name:
The netCDF variable name for the coordinate.
The netCDF variable name for the cell measure.
* units
The :class:`~cf_units.Unit` of the coordinate's values.
The :class:`~cf_units.Unit` of the cell measure's values.
Can be a string, which will be converted to a Unit object.
* attributes
A dictionary containing other CF and user-defined attributes.
Expand All @@ -2092,16 +2092,16 @@ def __init__(self, data, standard_name=None, long_name=None,
are the only valid entries.

"""
#: CF standard name of the quantity that the coordinate represents.
#: CF standard name of the quantity that the cell measure represents.
self.standard_name = standard_name

#: Descriptive name of the coordinate.
#: Descriptive name of the cell measure.
self.long_name = long_name

#: The netCDF variable name for the coordinate.
#: The netCDF variable name for the cell measure.
self.var_name = var_name

#: Unit of the quantity that the coordinate represents.
#: Unit of the quantity that the cell measure represents.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lbdreyer Nice spot... clearly cut'n paste syndrom 🤣

self.units = units

#: Other attributes, including user specified attributes that
Expand Down Expand Up @@ -2131,11 +2131,6 @@ def data(self, data):
if data is None:
raise ValueError('The data payload of a CellMeasure may not be '
'None; it must be a numpy array or equivalent.')
if _lazy.is_lazy_data(data) and data.dtype.kind in 'biu':
# Non-floating cell measures are not valid up to CF v1.7
msg = ('Cannot create cell measure with lazy data of type {}, as '
'integer types are not currently supported.')
raise ValueError(msg.format(data.dtype))
if data.shape == ():
# If we have a scalar value, promote the shape from () to (1,).
# NOTE: this way also *realises* it. Don't think that matters.
Expand Down
14 changes: 1 addition & 13 deletions lib/iris/tests/unit/coords/test_CellMeasure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2015 - 2018, Met Office
# (C) British Crown Copyright 2015 - 2019, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -72,18 +72,6 @@ def test_set_data__lazy(self):
self.measure.data = new_vals
self.assertArrayEqual(self.measure.data, new_vals)

def test_set_data__int__lazy(self):
new_vals = as_lazy_data(np.array((1, 2, 3, 4), dtype=np.int32))
exp_emsg = "Cannot create cell measure with lazy data of type int32"
with self.assertRaisesRegexp(ValueError, exp_emsg):
self.measure.data = new_vals

def test_set_data__uint__lazy(self):
new_vals = as_lazy_data(np.array((1, 2, 3, 4), dtype=np.uint32))
exp_emsg = "Cannot create cell measure with lazy data of type uint32"
with self.assertRaisesRegexp(ValueError, exp_emsg):
self.measure.data = new_vals

def test_data_different_shape(self):
new_vals = np.array((1., 2., 3.))
msg = 'New data shape must match existing data shape.'
Expand Down