Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the Coord.cell method lazy #5693

Merged
merged 2 commits into from
Jan 18, 2024
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/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