Skip to content

Commit 5db15a5

Browse files
committed
review actions
1 parent 137d4a2 commit 5db15a5

File tree

12 files changed

+144
-85
lines changed

12 files changed

+144
-85
lines changed

lib/iris/aux_factory.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import dask.array as da
1515
import numpy as np
1616

17-
from iris.common import CFVariableMixin, CoordMetadata, MetadataFactory
17+
from iris.common import CFVariableMixin, CoordMetadata, MetadataManagerFactory
1818
import iris.coords
1919

2020

@@ -34,8 +34,8 @@ class AuxCoordFactory(CFVariableMixin, metaclass=ABCMeta):
3434

3535
def __init__(self):
3636
# Configure the metadata manager.
37-
if not hasattr(self, "_metadata"):
38-
self._metadata = MetadataFactory(CoordMetadata)
37+
if not hasattr(self, "_metadata_manager"):
38+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
3939

4040
#: Descriptive name of the coordinate made by the factory
4141
self.long_name = None
@@ -45,19 +45,19 @@ def __init__(self):
4545

4646
self.coord_system = None
4747
# See the climatological property getter.
48-
self._metadata.climatological = False
48+
self._metadata_manager.climatological = False
4949

5050
@property
5151
def coord_system(self):
5252
"""
5353
The coordinate-system (if any) of the coordinate made by the factory.
5454
5555
"""
56-
return self._metadata.coord_system
56+
return self._metadata_manager.coord_system
5757

5858
@coord_system.setter
5959
def coord_system(self, value):
60-
self._metadata.coord_system = value
60+
self._metadata_manager.coord_system = value
6161

6262
@property
6363
def climatological(self):
@@ -66,7 +66,7 @@ def climatological(self):
6666
and therefore can never be climatological by definition.
6767
6868
"""
69-
return self._metadata.climatological
69+
return self._metadata_manager.climatological
7070

7171
@property
7272
@abstractmethod
@@ -385,7 +385,7 @@ def __init__(self, delta=None, sigma=None, orography=None):
385385
386386
"""
387387
# Configure the metadata manager.
388-
self._metadata = MetadataFactory(CoordMetadata)
388+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
389389
super().__init__()
390390

391391
if delta and delta.nbounds not in (0, 2):
@@ -574,7 +574,7 @@ def __init__(self, delta=None, sigma=None, surface_air_pressure=None):
574574
575575
"""
576576
# Configure the metadata manager.
577-
self._metadata = MetadataFactory(CoordMetadata)
577+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
578578
super().__init__()
579579

580580
# Check that provided coords meet necessary conditions.
@@ -779,7 +779,7 @@ def __init__(
779779
780780
"""
781781
# Configure the metadata manager.
782-
self._metadata = MetadataFactory(CoordMetadata)
782+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
783783
super().__init__()
784784

785785
# Check that provided coordinates meet necessary conditions.
@@ -1080,7 +1080,7 @@ def __init__(self, sigma=None, eta=None, depth=None):
10801080
10811081
"""
10821082
# Configure the metadata manager.
1083-
self._metadata = MetadataFactory(CoordMetadata)
1083+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
10841084
super().__init__()
10851085

10861086
# Check that provided coordinates meet necessary conditions.
@@ -1263,7 +1263,7 @@ def __init__(self, s=None, c=None, eta=None, depth=None, depth_c=None):
12631263
12641264
"""
12651265
# Configure the metadata manager.
1266-
self._metadata = MetadataFactory(CoordMetadata)
1266+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
12671267
super().__init__()
12681268

12691269
# Check that provided coordinates meet necessary conditions.
@@ -1486,7 +1486,7 @@ def __init__(
14861486
14871487
"""
14881488
# Configure the metadata manager.
1489-
self._metadata = MetadataFactory(CoordMetadata)
1489+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
14901490
super().__init__()
14911491

14921492
# Check that provided coordinates meet necessary conditions.
@@ -1704,7 +1704,7 @@ def __init__(self, s=None, c=None, eta=None, depth=None, depth_c=None):
17041704
17051705
"""
17061706
# Configure the metadata manager.
1707-
self._metadata = MetadataFactory(CoordMetadata)
1707+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
17081708
super().__init__()
17091709

17101710
# Check that provided coordinates meet necessary conditions.

lib/iris/common/metadata.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
"CellMeasureMetadata",
1818
"CoordMetadata",
1919
"CubeMetadata",
20-
"MetadataFactory",
20+
"MetadataManagerFactory",
2121
]
2222

2323

2424
# https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_data_set_components.html#object_name
2525
_TOKEN_PARSE = re.compile(r"""^[a-zA-Z0-9][\w\.\+\-@]*$""")
2626

2727

28-
class _BaseMeta(ABCMeta):
28+
class _NamedTupleMeta(ABCMeta):
2929
"""
3030
Meta-class to support the convenience of creating a namedtuple from
3131
names/members of the metadata class hierarchy.
@@ -71,7 +71,7 @@ def __new__(mcs, name, bases, namespace):
7171
return super().__new__(mcs, name, bases, namespace)
7272

7373

74-
class BaseMetadata(metaclass=_BaseMeta):
74+
class BaseMetadata(metaclass=_NamedTupleMeta):
7575
"""
7676
Container for common metadata.
7777
@@ -154,7 +154,8 @@ def _check(item):
154154
def __lt__(self, other):
155155
#
156156
# Support Python2 behaviour for a "<" operation involving a
157-
# "NoneType" operand.
157+
# "NoneType" operand. Require to at least implement this comparison
158+
# operator to support sorting of instances.
158159
#
159160
if not isinstance(other, self.__class__):
160161
return NotImplemented
@@ -242,7 +243,7 @@ def _check(item):
242243
@property
243244
def _names(self):
244245
"""
245-
A tuple containing the value of each name participating in the identify
246+
A tuple containing the value of each name participating in the identity
246247
of a :class:`iris.cube.Cube`. This includes the standard name,
247248
long name, NetCDF variable name, and the STASH from the attributes
248249
dictionary.
@@ -267,7 +268,7 @@ def _names(self):
267268
return (standard_name, long_name, var_name, stash_name)
268269

269270

270-
def MetadataFactory(cls, **kwargs):
271+
def MetadataManagerFactory(cls, **kwargs):
271272
"""
272273
A class instance factory function responsible for manufacturing
273274
metadata instances dynamically at runtime.
@@ -333,7 +334,7 @@ def __reduce__(self):
333334
instance, and dump and load instance state successfully.
334335
335336
"""
336-
return (MetadataFactory, (self.cls,), self.__getstate__())
337+
return (MetadataManagerFactory, (self.cls,), self.__getstate__())
337338

338339
def __repr__(self):
339340
args = ", ".join(
@@ -373,7 +374,7 @@ def values(self):
373374
raise ValueError(emsg.format(cls.__name__, bad))
374375

375376
# Define the name, (inheritance) bases and namespace of the dynamic class.
376-
name = "Metadata"
377+
name = "MetadataManager"
377378
bases = ()
378379
namespace = {
379380
"DEFAULT_NAME": cls.DEFAULT_NAME,

lib/iris/common/mixin.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def update(self, other, **kwargs):
121121
class CFVariableMixin:
122122
@wraps(BaseMetadata.name)
123123
def name(self, default=None, token=None):
124-
return self._metadata.name(default=default, token=token)
124+
return self._metadata_manager.name(default=default, token=token)
125125

126126
def rename(self, name):
127127
"""
@@ -145,60 +145,62 @@ def rename(self, name):
145145
@property
146146
def standard_name(self):
147147
"""The CF Metadata standard name for the object."""
148-
return self._metadata.standard_name
148+
return self._metadata_manager.standard_name
149149

150150
@standard_name.setter
151151
def standard_name(self, name):
152-
self._metadata.standard_name = _get_valid_standard_name(name)
152+
self._metadata_manager.standard_name = _get_valid_standard_name(name)
153153

154154
@property
155155
def long_name(self):
156156
"""The CF Metadata long name for the object."""
157-
return self._metadata.long_name
157+
return self._metadata_manager.long_name
158158

159159
@long_name.setter
160160
def long_name(self, name):
161-
self._metadata.long_name = name
161+
self._metadata_manager.long_name = name
162162

163163
@property
164164
def var_name(self):
165165
"""The NetCDF variable name for the object."""
166-
return self._metadata.var_name
166+
return self._metadata_manager.var_name
167167

168168
@var_name.setter
169169
def var_name(self, name):
170170
if name is not None:
171-
result = self._metadata.token(name)
171+
result = self._metadata_manager.token(name)
172172
if result is None or not name:
173173
emsg = "{!r} is not a valid NetCDF variable name."
174174
raise ValueError(emsg.format(name))
175-
self._metadata.var_name = name
175+
self._metadata_manager.var_name = name
176176

177177
@property
178178
def units(self):
179179
"""The S.I. unit of the object."""
180-
return self._metadata.units
180+
return self._metadata_manager.units
181181

182182
@units.setter
183183
def units(self, unit):
184-
self._metadata.units = cf_units.as_unit(unit)
184+
self._metadata_manager.units = cf_units.as_unit(unit)
185185

186186
@property
187187
def attributes(self):
188-
return self._metadata.attributes
188+
return self._metadata_manager.attributes
189189

190190
@attributes.setter
191191
def attributes(self, attributes):
192-
self._metadata.attributes = LimitedAttributeDict(attributes or {})
192+
self._metadata_manager.attributes = LimitedAttributeDict(
193+
attributes or {}
194+
)
193195

194196
@property
195197
def metadata(self):
196-
return self._metadata.values
198+
return self._metadata_manager.values
197199

198200
@metadata.setter
199201
def metadata(self, metadata):
200-
cls = self._metadata.cls
201-
fields = self._metadata.fields
202+
cls = self._metadata_manager.cls
203+
fields = self._metadata_manager.fields
202204
arg = metadata
203205

204206
try:

lib/iris/coords.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
CFVariableMixin,
3232
CellMeasureMetadata,
3333
CoordMetadata,
34-
MetadataFactory,
34+
MetadataManagerFactory,
3535
)
3636
import iris.exceptions
3737
import iris.time
@@ -98,8 +98,8 @@ def __init__(
9898
# it provides is a 'has_bounds()' method, which always returns False.
9999

100100
# Configure the metadata manager.
101-
if not hasattr(self, "_metadata"):
102-
self._metadata = MetadataFactory(BaseMetadata)
101+
if not hasattr(self, "_metadata_manager"):
102+
self._metadata_manager = MetadataManagerFactory(BaseMetadata)
103103

104104
#: CF standard name of the quantity that the metadata represents.
105105
self.standard_name = standard_name
@@ -709,8 +709,10 @@ def __init__(
709709
710710
"""
711711
# Configure the metadata manager.
712-
if not hasattr(self, "_metadata"):
713-
self._metadata = MetadataFactory(AncillaryVariableMetadata)
712+
if not hasattr(self, "_metadata_manager"):
713+
self._metadata_manager = MetadataManagerFactory(
714+
AncillaryVariableMetadata
715+
)
714716

715717
super().__init__(
716718
values=data,
@@ -820,7 +822,7 @@ def __init__(
820822
821823
"""
822824
# Configure the metadata manager.
823-
self._metadata = MetadataFactory(CellMeasureMetadata)
825+
self._metadata_manager = MetadataManagerFactory(CellMeasureMetadata)
824826

825827
super().__init__(
826828
data=data,
@@ -839,14 +841,14 @@ def __init__(
839841

840842
@property
841843
def measure(self):
842-
return self._metadata.measure
844+
return self._metadata_manager.measure
843845

844846
@measure.setter
845847
def measure(self, measure):
846848
if measure not in ["area", "volume"]:
847849
emsg = f"measure must be 'area' or 'volume', got {measure!r}"
848850
raise ValueError(emsg)
849-
self._metadata.measure = measure
851+
self._metadata_manager.measure = measure
850852

851853
def __str__(self):
852854
result = repr(self)
@@ -1319,7 +1321,7 @@ def __init__(
13191321
13201322
"""
13211323
# Configure the metadata manager.
1322-
self._metadata = MetadataFactory(CoordMetadata)
1324+
self._metadata_manager = MetadataManagerFactory(CoordMetadata)
13231325

13241326
super().__init__(
13251327
values=points,
@@ -1438,11 +1440,11 @@ def bounds(self, bounds):
14381440
@property
14391441
def coord_system(self):
14401442
"""The coordinate-system of the coordinate."""
1441-
return self._metadata.coord_system
1443+
return self._metadata_manager.coord_system
14421444

14431445
@coord_system.setter
14441446
def coord_system(self, value):
1445-
self._metadata.coord_system = value
1447+
self._metadata_manager.coord_system = value
14461448

14471449
@property
14481450
def climatological(self):
@@ -1457,10 +1459,10 @@ def climatological(self):
14571459
14581460
"""
14591461
if not self.has_bounds():
1460-
self._metadata.climatological = False
1462+
self._metadata_manager.climatological = False
14611463
if not self.units.is_time_reference():
1462-
self._metadata.climatological = False
1463-
return self._metadata.climatological
1464+
self._metadata_manager.climatological = False
1465+
return self._metadata_manager.climatological
14641466

14651467
@climatological.setter
14661468
def climatological(self, value):
@@ -1478,7 +1480,7 @@ def climatological(self, value):
14781480
emsg = "Cannot set climatological coordinate, no bounds exist."
14791481
raise ValueError(emsg)
14801482

1481-
self._metadata.climatological = value
1483+
self._metadata_manager.climatological = value
14821484

14831485
def lazy_points(self):
14841486
"""

0 commit comments

Comments
 (0)