Skip to content

Commit

Permalink
remove from metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
HGWright committed Nov 9, 2023
1 parent d42a2b7 commit 875f827
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
8 changes: 4 additions & 4 deletions lib/iris/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ class CoordMetadata(BaseMetadata):
"""

_members = ("coord_system", "climatological", "guess_coord")
_members = ("coord_system", "climatological")

__slots__ = ()

Expand Down Expand Up @@ -970,7 +970,7 @@ def _combine_lenient(self, other):
"""

# Perform "strict" combination for "coord_system", "climatological" and "guess_coord".
# Perform "strict" combination for "coord_system" and "climatological".
def func(field):
left = getattr(self, field)
right = getattr(other, field)
Expand Down Expand Up @@ -998,7 +998,7 @@ def _compare_lenient(self, other):
Boolean.
"""
# Perform "strict" comparison for "coord_system", "climatological" and "guess_coord".
# Perform "strict" comparison for "coord_system" and "climatological".
result = all(
[
getattr(self, field) == getattr(other, field)
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def _difference_lenient(self, other):
"""

# Perform "strict" difference for "coord_system", "climatological" and "guess_coord".
# Perform "strict" difference for "coord_system" and "climatological".
def func(field):
left = getattr(self, field)
right = getattr(other, field)
Expand Down
36 changes: 24 additions & 12 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import iris.time
import iris.util

#: The default value for ignore_axis which controls guess_coord_axis' behaviour
DEFAULT_IGNORE_AXIS = False


class _DimensionalMetadata(CFVariableMixin, metaclass=ABCMeta):
"""
Expand Down Expand Up @@ -1609,7 +1612,7 @@ def __init__(
self.bounds = bounds
self.climatological = climatological

self.guess_coord = True
self._ignore_axis = DEFAULT_IGNORE_AXIS

def copy(self, points=None, bounds=None):
"""
Expand Down Expand Up @@ -1643,6 +1646,10 @@ def copy(self, points=None, bounds=None):
# self.
new_coord.bounds = bounds

# The state of ignore_axis is controlled by the coordinate rather than
# the metadata manager
new_coord.ignore_axis = self.ignore_axis

return new_coord

@classmethod
Expand All @@ -1662,7 +1669,14 @@ def from_coord(cls, coord):
if issubclass(cls, DimCoord):
# DimCoord introduces an extra constructor keyword.
kwargs["circular"] = getattr(coord, "circular", False)
return cls(**kwargs)

new_coord = cls(**kwargs)

# The state of ignore_axis is controlled by the coordinate rather than
# the metadata manager
new_coord.ignore_axis = coord.ignore_axis

return new_coord

@property
def points(self):
Expand Down Expand Up @@ -1755,24 +1769,22 @@ def climatological(self, value):
self._metadata_manager.climatological = value

@property
def guess_coord(self):
def ignore_axis(self):
"""
A boolean that controls whether guess_coord_axis acts on this
coordinate.
Defaults to True, and when set to False it will be skipped by
Defaults to False, and when set to True it will be skipped by
guess_coord_axis.
"""
return self._metadata_manager.guess_coord
return self._ignore_axis

@guess_coord.setter
def guess_coord(self, value):
if value is not True and value is not False:
emsg = "Guess_coord can only be set to True or False"
@ignore_axis.setter
def ignore_axis(self, value):
if not isinstance(value, bool):
emsg = "Ignore_axis can only be set to True or False"
raise ValueError(emsg)
else:
pass
self._metadata_manager.guess_coord = value
self._ignore_axis = value

def lazy_points(self):
"""
Expand Down
17 changes: 5 additions & 12 deletions lib/iris/tests/unit/common/metadata/test_CoordMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def setUp(self):
self.attributes = mock.sentinel.attributes
self.coord_system = mock.sentinel.coord_system
self.climatological = mock.sentinel.climatological
self.guess_coord = mock.sentinel.guess_coord
self.cls = CoordMetadata

def test_repr(self):
Expand All @@ -41,12 +40,11 @@ def test_repr(self):
attributes=self.attributes,
coord_system=self.coord_system,
climatological=self.climatological,
guess_coord=self.guess_coord
)
fmt = (
"CoordMetadata(standard_name={!r}, long_name={!r}, "
"var_name={!r}, units={!r}, attributes={!r}, coord_system={!r}, "
"climatological={!r}, guess_coord={!r})"
"climatological={!r})"
)
expected = fmt.format(
self.standard_name,
Expand All @@ -56,7 +54,6 @@ def test_repr(self):
self.attributes,
self.coord_system,
self.climatological,
self.guess_coord,
)
self.assertEqual(expected, repr(metadata))

Expand All @@ -69,7 +66,6 @@ def test__fields(self):
"attributes",
"coord_system",
"climatological",
"guess_coord",
)
self.assertEqual(self.cls._fields, expected)

Expand All @@ -87,7 +83,6 @@ def setUp(self):
attributes=sentinel.attributes,
coord_system=sentinel.coord_system,
climatological=sentinel.climatological,
guess_coord=sentinel.guess_coord
)
self.dummy = sentinel.dummy
self.cls = CoordMetadata
Expand Down Expand Up @@ -228,10 +223,10 @@ def test_op_strict_different_members_none(self):
class Test___lt__(tests.IrisTest):
def setUp(self):
self.cls = CoordMetadata
self.one = self.cls(1, 1, 1, 1, 1, 1, 1, 1)
self.two = self.cls(1, 1, 1, 2, 1, 1, 1, 1)
self.none = self.cls(1, 1, 1, None, 1, 1, 1, 1)
self.attributes_cs = self.cls(1, 1, 1, 1, 10, 10, 1, 1)
self.one = self.cls(1, 1, 1, 1, 1, 1, 1)
self.two = self.cls(1, 1, 1, 2, 1, 1, 1)
self.none = self.cls(1, 1, 1, None, 1, 1, 1)
self.attributes_cs = self.cls(1, 1, 1, 1, 10, 10, 1)

def test__ascending_lt(self):
result = self.one < self.two
Expand Down Expand Up @@ -266,7 +261,6 @@ def setUp(self):
attributes=sentinel.attributes,
coord_system=sentinel.coord_system,
climatological=sentinel.climatological,
guess_coord=sentinel.guess_coord
)
self.dummy = sentinel.dummy
self.cls = CoordMetadata
Expand Down Expand Up @@ -463,7 +457,6 @@ def setUp(self):
attributes=sentinel.attributes,
coord_system=sentinel.coord_system,
climatological=sentinel.climatological,
guess_coord=sentinel.guess_coord,
)
self.dummy = sentinel.dummy
self.cls = CoordMetadata
Expand Down
17 changes: 6 additions & 11 deletions lib/iris/tests/unit/coords/test_Coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,26 +1157,21 @@ def coord():
return coord


class Test_guess_coord:
class Test_ignore_axis:
def test_default(self, coord):

assert coord.guess_coord is True
assert coord.ignore_axis is False

def test_set_true(self, coord):
coord.guess_coord = True
coord.ignore_axis = True

assert coord.guess_coord is True

def test_set_false(self, coord):
coord.guess_coord = False

assert coord.guess_coord is False
assert coord.ignore_axis is True

def test_set_random_value(self, coord):
with pytest.raises(
ValueError, match=r"Guess_coord can only be set to True or False"
ValueError, match=r"Ignore_axis can only be set to True or False"
):
coord.guess_coord = "foo"
coord.ignore_axis = "foo"


class Test___init____abstractmethod(tests.IrisTest):
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/unit/util/test_guess_coord_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ def test_time_units(self, coord):

def test_guess_coord(self, coord):
coord.standard_name = "longitude"
coord.guess_coord = False
coord.ignore_axis = True

assert guess_coord_axis(coord) is None
4 changes: 2 additions & 2 deletions lib/iris/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ def guess_coord_axis(coord):
This function maintains laziness when called; it does not realise data.
See more at :doc:`/userguide/real_and_lazy_data`.
``guess_coord_axis`` can be skipped by setting the coordinate property of a coord guess_coord
``guess_coord_axis`` can be skipped by setting the coordinate property of a coord ignore_axis
to False.
"""

axis = None

if coord.guess_coord is False:
if coord.ignore_axis is True:

return axis

Expand Down

0 comments on commit 875f827

Please sign in to comment.