Skip to content

Commit c4a7642

Browse files
rcomertrexfeathers
andauthored
Fix guess_bounds precision for circular coords at numpy v2 (#6793)
* Fix guess_bounds precision for circular coords at numpy v2 * Apply review suggestion Co-authored-by: Martin Yeo <[email protected]> --------- Co-authored-by: Martin Yeo <[email protected]>
1 parent f09a4e0 commit c4a7642

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

docs/src/whatsnew/3.14.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ This document explains the changes made to Iris for this release
4646
And finally, get in touch with us on :issue:`GitHub<new/choose>` if you have
4747
any issues or feature requests for improving Iris. Enjoy!
4848

49+
v3.14.1 (Date TBD)
50+
==================
51+
52+
.. dropdown:: v3.14.1 Patches
53+
:color: primary
54+
:icon: alert
55+
:animate: fade-in
56+
:open:
57+
58+
The patches in this release of Iris include:
59+
60+
#. Fixed compatibility with NumPy v2 for :meth:`~iris.coords.Coord.guess_bounds`
61+
:ref:`See the full entry for more<3_14_1_guess_bounds>`.
4962

5063
✨ Features
5164
===========
@@ -112,6 +125,12 @@ This document explains the changes made to Iris for this release
112125
error, caused by bad synchronisation between Python-layer and HDF-layer
113126
file locking on certain filesystems. (:pull:`6760`).
114127

128+
.. _3_14_1_guess_bounds:
129+
130+
#. `@rcomer`_ ensured that :meth:`~iris.coords.Coord.guess_bounds` calculates at
131+
double precision for circular coordinates so the bounds span the full circle
132+
(:issue:`6738`, :pull:`6793`)
133+
115134

116135
💣 Incompatible Changes
117136
=======================

lib/iris/coords.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,8 +2402,12 @@ def _guess_bounds(self, bound_position=0.5, monthly=False, yearly=False):
24022402
points = np.empty(self.shape[0] + 2)
24032403
points[1:-1] = self.points
24042404
direction = 1 if self.points[-1] > self.points[0] else -1
2405-
points[0] = self.points[-1] - (self.units.modulus * direction)
2406-
points[-1] = self.points[0] + (self.units.modulus * direction)
2405+
modulus_type = np.promote_types(
2406+
self.points.dtype, type(self.units.modulus)
2407+
)
2408+
(modulus,) = np.array([self.units.modulus], dtype=modulus_type)
2409+
points[0] = self.points[-1] - (modulus * direction)
2410+
points[-1] = self.points[0] + (modulus * direction)
24072411
diffs = np.diff(points)
24082412
else:
24092413
diffs = np.diff(self.points)

lib/iris/tests/unit/coords/test_Coord.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ def test_circular_decreasing_alt_range(self):
194194
)
195195
_shared_utils.assert_array_equal(target, self.coord.bounds)
196196

197+
def test_circular_n216_float32(self):
198+
# Values represent longitude taken from an N216 pp-file.
199+
coord = DimCoord.from_regular(
200+
-0.41666666, 0.8333333, 432, units="degrees", circular=True
201+
)
202+
coord.guess_bounds()
203+
# The last bound should match up to the first.
204+
assert coord.bounds[-1, -1] - coord.bounds[0, 0] == 360
205+
197206

198207
class Test_guess_bounds__default_enabled_latitude_clipping:
199208
def test_all_inside(self):

0 commit comments

Comments
 (0)