Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
HGWright committed Nov 17, 2023
1 parent cffa5b6 commit a9a45d1
Showing 3 changed files with 75 additions and 61 deletions.
47 changes: 27 additions & 20 deletions lib/iris/tests/unit/coords/test_Coord.py
Original file line number Diff line number Diff line change
@@ -1152,35 +1152,42 @@ def test_change_units(self):


@pytest.fixture
def coord():
coord = iris.coords.DimCoord(points=(1, 2, 3, 4, 5))
return coord
def sample_coord():
sample_coord = iris.coords.DimCoord(points=(1, 2, 3, 4, 5))
return sample_coord


class Test_ignore_axis:
def test_default(self, coord):
assert coord.ignore_axis is False
def test_default(self, sample_coord):
assert sample_coord.ignore_axis is False

def test_set_true(self, coord):
coord.ignore_axis = True
assert coord.ignore_axis is True
def test_set_true(self, sample_coord):
sample_coord.ignore_axis = True
assert sample_coord.ignore_axis is True

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

def test_copy_coord(self, coord):
coord.ignore_axis = True
coord_copy = coord.copy()
assert coord_copy.ignore_axis is True

def test_from_coord(self, coord):
coord.ignore_axis = True
new_coord = coord.from_coord(coord)
assert new_coord.ignore_axis is True
sample_coord.ignore_axis = "foo"

@pytest.mark.parametrize(
"ignore_axis, copy_or_from, result",
[
(True, "copy", True),
(True, "from_coord", True),
(False, "copy", False),
(False, "from_coord", False),
],
)
def test_copy_coord(self, ignore_axis, copy_or_from, result, sample_coord):
sample_coord.ignore_axis = ignore_axis
if copy_or_from == "copy":
new_coord = sample_coord.copy()
elif copy_or_from == "from_coord":
new_coord = sample_coord.from_coord(sample_coord)
assert new_coord.ignore_axis is result


class Test___init____abstractmethod(tests.IrisTest):
85 changes: 46 additions & 39 deletions lib/iris/tests/unit/util/test_guess_coord_axis.py
Original file line number Diff line number Diff line change
@@ -3,49 +3,56 @@
# This file is part of Iris and is released under the LGPL license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
"""Test function :func:`iris.util.guess_coord_axis"""
"""Test function :func:`iris.util.guess_coord_axis`."""

import pytest

import iris.coords
from iris.util import guess_coord_axis


@pytest.fixture
def coord():
coord = iris.coords.DimCoord(points=(1, 2, 3, 4, 5))
return coord


@pytest.mark.parametrize(
"coordinate, axis",
[
("longitude", "X"),
("grid_longitude", "X"),
("projection_x_coordinate", "X"),
("latitude", "Y"),
("grid_latitude", "Y"),
("projection_y_coordinate", "Y"),
],
)
def testcoord(coordinate, axis, coord):
coord.standard_name = coordinate
assert guess_coord_axis(coord) == axis


class TestCoords:
def test_pressure_units(self, coord):
coord.units = "hPa"

assert guess_coord_axis(coord) == "Z"

def test_time_units(self, coord):
coord.units = "days since 1970-01-01 00:00:00"

assert guess_coord_axis(coord) == "T"

def test_ignore_axis(self, coord):
coord.standard_name = "longitude"
coord.ignore_axis = True

assert guess_coord_axis(coord) is None
class TestGuessCoord:

@pytest.fixture
def sample_coord(self):
sample_coord = iris.coords.DimCoord(points=(1, 2, 3, 4, 5))
return sample_coord

@pytest.mark.parametrize(
"coordinate, axis",
[
("longitude", "X"),
("grid_longitude", "X"),
("projection_x_coordinate", "X"),
("latitude", "Y"),
("grid_latitude", "Y"),
("projection_y_coordinate", "Y"),
],
)
def test_coord(self, coordinate, axis, sample_coord):
sample_coord.standard_name = coordinate
assert guess_coord_axis(sample_coord) == axis

@pytest.mark.parametrize(
"units, axis",
[
("hPa", "Z"),
("days since 1970-01-01 00:00:00", "T"),
],
)
def test_units(self, units, axis, sample_coord):
sample_coord.units = units
assert guess_coord_axis(sample_coord) == axis

@pytest.mark.parametrize(
"ignore_axis, result",
[
(True, None),
(False, "X"),
],
)
def test_ignore_axis(self, ignore_axis, result, sample_coord):
sample_coord.standard_name = "longitude"
sample_coord.ignore_axis = ignore_axis

assert guess_coord_axis(sample_coord) == result
4 changes: 2 additions & 2 deletions lib/iris/util.py
Original file line number Diff line number Diff line change
@@ -258,8 +258,8 @@ 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 ignore_axis
to False.
The ``guess_coord_axis`` behaviour can be skipped by setting the coordinate property ``ignore_axis``
to ``False``.
"""

0 comments on commit a9a45d1

Please sign in to comment.