Skip to content

Commit 4829ab7

Browse files
committed
Make the Coord.cell method lazy
1 parent b11af45 commit 4829ab7

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

docs/src/whatsnew/latest.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ This document explains the changes made to Iris for this release
100100
lazy data from file. This will also speed up coordinate comparison.
101101
(:pull:`5610`)
102102

103+
#. `@bouweandela`_ changed :func:`iris.coords.Coord.cell` so it does not realize
104+
all coordinate data and only loads a single cell instead. (:pull:`5693`)
103105

104106
🔥 Deprecations
105107
===============

lib/iris/coords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ def cell(self, index):
20922092
"""
20932093
index = iris.util._build_full_slice_given_keys(index, self.ndim)
20942094

2095-
point = tuple(np.array(self.points[index], ndmin=1).flatten())
2095+
point = tuple(np.array(self.core_points()[index], ndmin=1).flatten())
20962096
if len(point) != 1:
20972097
raise IndexError(
20982098
"The index %s did not uniquely identify a single "
@@ -2101,7 +2101,7 @@ def cell(self, index):
21012101

21022102
bound = None
21032103
if self.has_bounds():
2104-
bound = tuple(np.array(self.bounds[index], ndmin=1).flatten())
2104+
bound = tuple(np.array(self.core_bounds()[index], ndmin=1).flatten())
21052105

21062106
if self.units.is_time_reference():
21072107
point = self.units.num2date(point)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,12 @@ def _mock_coord(self):
240240
coord = mock.Mock(
241241
spec=Coord,
242242
ndim=1,
243-
points=np.array([mock.sentinel.time]),
244-
bounds=np.array([[mock.sentinel.lower, mock.sentinel.upper]]),
245243
)
244+
coord.core_points = lambda: np.array([mock.sentinel.time])
245+
coord.core_bounds = lambda: np.array(
246+
[[mock.sentinel.lower, mock.sentinel.upper]]
247+
)
248+
246249
return coord
247250

248251
def test_time_as_object(self):

0 commit comments

Comments
 (0)