From c0b723f70779d19a41ee7855ad62cbf1ebca9ca4 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Wed, 2 Mar 2022 16:14:37 +0000 Subject: [PATCH 1/5] add failing test --- .../tests/unit/plot/test__get_plot_objects.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/iris/tests/unit/plot/test__get_plot_objects.py diff --git a/lib/iris/tests/unit/plot/test__get_plot_objects.py b/lib/iris/tests/unit/plot/test__get_plot_objects.py new file mode 100644 index 0000000000..0b3ea17366 --- /dev/null +++ b/lib/iris/tests/unit/plot/test__get_plot_objects.py @@ -0,0 +1,29 @@ +# Copyright Iris contributors +# +# 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. +"""Unit tests for the `iris.plot._get_plot_objects` function.""" + +# Import iris.tests first so that some things can be initialised before +# importing anything else. +import iris.tests as tests # isort:skip + +import iris.cube + +if tests.MPL_AVAILABLE: + from iris.plot import _get_plot_objects + + +@tests.skip_plot +class Test_get_plot_objects(tests.IrisTest): + def test_scalar(self): + cube1 = iris.cube.Cube(1) + cube2 = iris.cube.Cube(1) + expected = (cube1, cube2, 1, 1, ()) + result = _get_plot_objects((cube1, cube2)) + self.assertTupleEqual(expected, result) + + +if __name__ == "__main__": + tests.main() From 50b923d252539abeffa5941d932525d8288e7798 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Wed, 2 Mar 2022 16:32:33 +0000 Subject: [PATCH 2/5] pass test --- lib/iris/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/plot.py b/lib/iris/plot.py index aefca889cf..0fc6109dfc 100644 --- a/lib/iris/plot.py +++ b/lib/iris/plot.py @@ -652,7 +652,7 @@ def _get_plot_objects(args): u_object, v_object = args[:2] u, v = _uv_from_u_object_v_object(u_object, v_object) args = args[2:] - if len(u) != len(v): + if u.size != v.size: msg = ( "The x and y-axis objects are not compatible. They should " "have equal sizes but got ({}: {}) and ({}: {})." From 33a73542207e2d176c0ec1a5fd93fcd86b24ae39 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Fri, 4 Mar 2022 17:08:56 +0000 Subject: [PATCH 3/5] initial review actions --- lib/iris/plot.py | 2 +- lib/iris/tests/unit/plot/test__get_plot_objects.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/iris/plot.py b/lib/iris/plot.py index 0fc6109dfc..d886ac1cf9 100644 --- a/lib/iris/plot.py +++ b/lib/iris/plot.py @@ -658,7 +658,7 @@ def _get_plot_objects(args): "have equal sizes but got ({}: {}) and ({}: {})." ) raise ValueError( - msg.format(u_object.name(), len(u), v_object.name(), len(v)) + msg.format(u_object.name(), u.size, v_object.name(), v.size) ) else: # single argument diff --git a/lib/iris/tests/unit/plot/test__get_plot_objects.py b/lib/iris/tests/unit/plot/test__get_plot_objects.py index 0b3ea17366..78465bb392 100644 --- a/lib/iris/tests/unit/plot/test__get_plot_objects.py +++ b/lib/iris/tests/unit/plot/test__get_plot_objects.py @@ -16,7 +16,7 @@ @tests.skip_plot -class Test_get_plot_objects(tests.IrisTest): +class Test__get_plot_objects(tests.IrisTest): def test_scalar(self): cube1 = iris.cube.Cube(1) cube2 = iris.cube.Cube(1) @@ -24,6 +24,14 @@ def test_scalar(self): result = _get_plot_objects((cube1, cube2)) self.assertTupleEqual(expected, result) + def test_mismatched_size(self): + cube1 = iris.cube.Cube(1) + cube2 = iris.cube.Cube([1, 42]) + with self.assertRaisesRegex( + ValueError, "x and y-axis objects are not compatible" + ): + _get_plot_objects((cube1, cube2)) + if __name__ == "__main__": tests.main() From 2628d6c3de5bf7f824ee53a3fb6bf2049f5e2ed5 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Tue, 8 Mar 2022 14:06:56 +0000 Subject: [PATCH 4/5] test 2nd arg scalar --- lib/iris/tests/unit/plot/test__get_plot_objects.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/iris/tests/unit/plot/test__get_plot_objects.py b/lib/iris/tests/unit/plot/test__get_plot_objects.py index 78465bb392..8586faa756 100644 --- a/lib/iris/tests/unit/plot/test__get_plot_objects.py +++ b/lib/iris/tests/unit/plot/test__get_plot_objects.py @@ -24,7 +24,7 @@ def test_scalar(self): result = _get_plot_objects((cube1, cube2)) self.assertTupleEqual(expected, result) - def test_mismatched_size(self): + def test_mismatched_size_first_scalar(self): cube1 = iris.cube.Cube(1) cube2 = iris.cube.Cube([1, 42]) with self.assertRaisesRegex( @@ -32,6 +32,14 @@ def test_mismatched_size(self): ): _get_plot_objects((cube1, cube2)) + def test_mismatched_size_second_scalar(self): + cube1 = iris.cube.Cube(1) + cube2 = iris.cube.Cube([1, 42]) + with self.assertRaisesRegex( + ValueError, "x and y-axis objects are not compatible" + ): + _get_plot_objects((cube2, cube1)) + if __name__ == "__main__": tests.main() From 160fb5be3e41f0b4a934ba87d6462891dff0fe5a Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Tue, 8 Mar 2022 14:16:56 +0000 Subject: [PATCH 5/5] whatsnew --- docs/src/whatsnew/dev.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/src/whatsnew/dev.rst b/docs/src/whatsnew/dev.rst index b9d5989bfc..5cc0769c57 100644 --- a/docs/src/whatsnew/dev.rst +++ b/docs/src/whatsnew/dev.rst @@ -41,6 +41,9 @@ This document explains the changes made to Iris for this release #. `@rcomer`_ reverted part of the change from :pull:`3906` so that :func:`iris.plot.plot` no longer defaults to placing a "Y" coordinate (e.g. latitude) on the y-axis of the plot. (:issue:`4493`, :pull:`4601`) + +#. `@rcomer`_ enabled passing of scalar objects to :func:`~iris.plot.plot` and + :func:`~iris.plot.scatter`. (:pull:`4616`) 💣 Incompatible Changes