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
4 changes: 4 additions & 0 deletions docs/src/whatsnew/dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ This document explains the changes made to Iris for this release
#. `@rcomer`_ ensured that a :class:`matplotlib.axes.Axes`'s position is preserved
when Iris replaces it with a :class:`cartopy.mpl.geoaxes.GeoAxes`, fixing
:issue:`1157`. (:pull:`4273`)

#. `@rcomer`_ fixed :meth:`~iris.coords.Coord.nearest_neighbour_index` for edge
cases where the requested point is float and the coordinate has integer
bounds, reported at :issue:`2969`. (:pull:`4245`)


💣 Incompatible Changes
Expand Down
4 changes: 3 additions & 1 deletion lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,9 @@ def nearest_neighbour_index(self, point):
if self.has_bounds():
# make bounds ranges complete+separate, so point is in at least one
increasing = self.bounds[0, 1] > self.bounds[0, 0]
bounds = bounds.copy()
# identify data type that bounds and point can safely cast to
dtype = np.result_type(bounds, point)
bounds = bounds.astype(dtype)
# sort the bounds cells by their centre values
sort_inds = np.argsort(np.mean(bounds, axis=1))
bounds = bounds[sort_inds]
Expand Down
5 changes: 5 additions & 0 deletions lib/iris/tests/unit/coords/test_Coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def test_scalar(self):
target = [0, 0, 0, 0, 0]
self._test_nearest_neighbour_index(target)

def test_bounded_float_point(self):
coord = DimCoord(1, bounds=[0, 2])
result = coord.nearest_neighbour_index(2.5)
self.assertEqual(result, 0)


class Test_nearest_neighbour_index__descending(tests.IrisTest):
def setUp(self):
Expand Down