Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,13 @@ 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 ({}: {})."
)
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
Expand Down
37 changes: 37 additions & 0 deletions lib/iris/tests/unit/plot/test__get_plot_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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)

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()