Skip to content

Commit

Permalink
Make the Coord.cell method lazy (#5693)
Browse files Browse the repository at this point in the history
Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com>
  • Loading branch information
bouweandela and ESadek-MO authored Jan 18, 2024
1 parent fe46e05 commit 66893f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ This document explains the changes made to Iris for this release
lazy data from file. This will also speed up coordinate comparison.
(:pull:`5610`)

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

#. `@rcomer`_ and `@trexfeathers`_ (reviewer) modified
:func:`~iris.analysis.stats.pearsonr` so it preserves lazy data in all cases
and also runs a little faster. (:pull:`5638`)


🔥 Deprecations
===============

Expand Down
4 changes: 2 additions & 2 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ def cell(self, index):
"""
index = iris.util._build_full_slice_given_keys(index, self.ndim)

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

bound = None
if self.has_bounds():
bound = tuple(np.array(self.bounds[index], ndmin=1).flatten())
bound = tuple(np.array(self.core_bounds()[index], ndmin=1).flatten())

if self.units.is_time_reference():
point = self.units.num2date(point)
Expand Down
7 changes: 5 additions & 2 deletions lib/iris/tests/unit/coords/test_Coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,12 @@ def _mock_coord(self):
coord = mock.Mock(
spec=Coord,
ndim=1,
points=np.array([mock.sentinel.time]),
bounds=np.array([[mock.sentinel.lower, mock.sentinel.upper]]),
)
coord.core_points = lambda: np.array([mock.sentinel.time])
coord.core_bounds = lambda: np.array(
[[mock.sentinel.lower, mock.sentinel.upper]]
)

return coord

def test_time_as_object(self):
Expand Down

0 comments on commit 66893f2

Please sign in to comment.