Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ This document explains the changes made to Iris for this release
as well as some long-standing bugs with vertical coordinates and number
formats. (:pull:`4411`)

#. `@rcomer`_ fixed :meth:`~iris.cube.Cube.subset` to alway return ``None`` if
no value match is found. (:pull:`4417`)

#. `@wjbenfold`_ resolved an issue that previously caused regridding with lazy
data to take significantly longer than with real data. Relevant benchmark
shows a time decrease from >10s to 625ms. (:issue:`4280`, :pull:`4400`)
Expand Down
4 changes: 4 additions & 0 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,10 @@ def subset(self, coord):
coord, return_indices=True
)

if coord_indices.size == 0:
# No matches found.
return

# Build up a slice which spans the whole of the cube
full_slice = [slice(None, None)] * len(self.shape)
# Update the full slice to only extract specific indices which
Expand Down
9 changes: 9 additions & 0 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,15 @@ def test_different_coordinate(self):
result = cube.subset(different_coord)
self.assertEqual(result, None)

def test_different_coordinate_vector(self):
cube = Cube([0, 1], long_name="raspberry", units="1")
cube.add_dim_coord(
DimCoord([0, 1], long_name="loganberry", units="1"), 0
)
different_coord = DimCoord([2], long_name="loganberry", units="1")
result = cube.subset(different_coord)
self.assertEqual(result, None)

def test_not_coordinate(self):
cube = Cube(0, long_name="peach", units="1")
cube.add_aux_coord(DimCoord([0], long_name="crocodile", units="1"))
Expand Down